Skip to content

Commit e04c6fb

Browse files
Merge pull request #62552 from nextcloud/carl/optimize-watcher
perf: Use hash map to check if path was already checked
2 parents c053d23 + f65ef83 commit e04c6fb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/private/Files/Cache/Watcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
class Watcher implements IWatcher {
2121
protected int $watchPolicy = self::CHECK_ONCE;
22+
/** @var array<string, true> $checkedPaths */
2223
protected array $checkedPaths = [];
2324
protected ICache $cache;
2425
protected IScanner $scanner;
@@ -121,8 +122,8 @@ public function needsUpdate($path, $cachedData) {
121122
}
122123
}
123124

124-
if ($this->watchPolicy === self::CHECK_ALWAYS || ($this->watchPolicy === self::CHECK_ONCE && !in_array($path, $this->checkedPaths))) {
125-
$this->checkedPaths[] = $path;
125+
if ($this->watchPolicy === self::CHECK_ALWAYS || ($this->watchPolicy === self::CHECK_ONCE && !isset($this->checkedPaths[$path]))) {
126+
$this->checkedPaths[$path] = true;
126127
return $cachedData['storage_mtime'] === null || $this->storage->hasUpdated($path, $cachedData['storage_mtime']);
127128
}
128129
return false;

0 commit comments

Comments
 (0)