Skip to content

Commit 37da5ff

Browse files
authored
Merge pull request #52040 from nextcloud/backport/52008/stable30
[stable30] fix: Proper order for checking path prefix for getting file by id from cache
2 parents 9b9bd3a + d38a431 commit 37da5ff

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/private/Files/Node/Root.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,17 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode {
389389
// scope the cache by user, so we don't return nodes for different users
390390
if ($this->user) {
391391
$cachedPath = $this->pathByIdCache->get($this->user->getUID() . '::' . $id);
392-
if ($cachedPath && str_starts_with($path, $cachedPath)) {
392+
if ($cachedPath && str_starts_with($cachedPath, $path)) {
393393
// getting the node by path is significantly cheaper than finding it by id
394-
$node = $this->get($cachedPath);
395-
// by validating that the cached path still has the requested fileid we can work around the need to invalidate the cached path
396-
// if the cached path is invalid or a different file now we fall back to the uncached logic
397-
if ($node && $node->getId() === $id) {
398-
return $node;
394+
try {
395+
$node = $this->get($cachedPath);
396+
// by validating that the cached path still has the requested fileid we can work around the need to invalidate the cached path
397+
// if the cached path is invalid or a different file now we fall back to the uncached logic
398+
if ($node && $node->getId() === $id) {
399+
return $node;
400+
}
401+
} catch (NotFoundException|NotPermittedException) {
402+
// The file may be moved but the old path still in cache
399403
}
400404
}
401405
}

0 commit comments

Comments
 (0)