Skip to content

Commit 8cdf6d0

Browse files
authored
Merge pull request #206 from nextcloud/perf/no-unnecessary-owner-check
perf(FsEventScheduler): Make sure to get node owner from caller, if possible
2 parents e47c472 + b496d5f commit 8cdf6d0

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/Listener/FileListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function handle(Event $event): void {
116116
if ($event instanceof \OCP\Files\Config\Event\UserMountAddedEvent) {
117117
$rootId = $event->mountPoint->getRootId();
118118
// Asynchronous, because we potentially recurse and this event needs to be handled fast
119-
$this->fsEventScheduler->onAccessUpdateDecl($rootId);
119+
$this->fsEventScheduler->onAccessUpdateDecl($rootId, $event->mountPoint->getUser()->getUID());
120120
// Remember that this mount was added in the current process (see UserMountRemovedEvent below)
121121
$this->addedMounts[$event->mountPoint->getUser()->getUID() . '-' . $rootId] = true;
122122
}
@@ -130,7 +130,7 @@ public function handle(Event $event): void {
130130
return;
131131
}
132132
// Asynchronous, because we potentially recurse and this event needs to be handled fast
133-
$this->fsEventScheduler->onAccessUpdateDecl($rootId);
133+
$this->fsEventScheduler->onAccessUpdateDecl($rootId, $event->mountPoint->getUser()->getUID());
134134
}
135135
} catch (InvalidPathException|Exception|NotFoundException $e) {
136136
$this->logger->warning('Error in fs event listener: ' . $e->getMessage(), ['exception' => $e]);

lib/Service/FsEventScheduler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ private function retractEvent(FsEventType $type, string $ownerId, int $nodeId) {
6363
* @throws NotFoundException
6464
* @throws Exception
6565
*/
66-
public function onAccessUpdateDecl(int $nodeId): void {
67-
$ownerId = $this->storageService->getOwnerForFileId($nodeId);
68-
if ($ownerId === false) {
69-
throw new NotFoundException('Cannot get owner for file ID ' . $nodeId);
66+
public function onAccessUpdateDecl(int $nodeId, ?string $ownerId = null): void {
67+
if ($ownerId === null) {
68+
$ownerId = $this->storageService->getOwnerForFileId($nodeId);
69+
if ($ownerId === false) {
70+
throw new NotFoundException('Cannot get owner for file ID ' . $nodeId);
71+
}
7072
}
7173
$this->scheduleEvent(FsEventType::ACCESS_UPDATE_DECL, $ownerId, $nodeId);
7274
}

0 commit comments

Comments
 (0)