Skip to content

Commit 50e9a95

Browse files
committed
fix: track time spent in recursive markOrRun calls
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent ee9ee69 commit 50e9a95

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class SharesUpdatedListener implements IEventListener {
4343
private float $cutOffMarkTime;
4444

4545
/**
46-
* The total amount of time we've spent so far processing updates
46+
* Timestamp marking the start of the current timing period
4747
*/
48-
private float $updatedTime = 0.0;
48+
private ?float $lastPeriodStart = null;
4949
private bool $inUpdate = false;
5050

5151
public function __construct(
@@ -134,14 +134,18 @@ public function handle(Event $event): void {
134134
}
135135

136136
private function markOrRun(IUser $user, callable $callback): void {
137-
$start = floatval($this->clock->now()->format('U.u'));
138-
if ($this->cutOffMarkTime === -1.0 || $this->updatedTime < $this->cutOffMarkTime) {
137+
$now = floatval($this->clock->now()->format('U.u'));
138+
$elapsed = $now - ($this->lastPeriodStart ?? $now);
139+
$this->lastPeriodStart = $now;
140+
141+
if ($this->cutOffMarkTime === -1.0 && $elapsed < $this->cutOffMarkTime) {
139142
$callback();
140143
} else {
141144
$this->markUserForRefresh($user);
142145
}
146+
143147
$end = floatval($this->clock->now()->format('U.u'));
144-
$this->updatedTime += $end - $start;
148+
$this->lastPeriodStart = $end;
145149
}
146150

147151
private function updateOrMarkUser(IUser $user): void {

0 commit comments

Comments
 (0)