From 49f22285708ed28bd443ff39fd1ec0060134157d Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Mon, 7 Apr 2025 20:47:11 +0200 Subject: [PATCH 1/2] fix: Proper order for checking path prefix for getting file by id from cache Signed-off-by: Julius Knorr --- lib/private/Files/Node/Root.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 1686051131dac..cf837cba397b5 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -384,7 +384,7 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode { // scope the cache by user, so we don't return nodes for different users if ($this->user) { $cachedPath = $this->pathByIdCache->get($this->user->getUID() . '::' . $id); - if ($cachedPath && str_starts_with($path, $cachedPath)) { + if ($cachedPath && str_starts_with($cachedPath, $path)) { // getting the node by path is significantly cheaper than finding it by id $node = $this->get($cachedPath); // by validating that the cached path still has the requested fileid we can work around the need to invalidate the cached path From e5209d4076aa06d48ba129281cacc783b772498d Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Tue, 8 Apr 2025 09:17:35 +0200 Subject: [PATCH 2/2] fix: Catch old cached paths and fetch the new one Signed-off-by: Julius Knorr --- lib/private/Files/Node/Root.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index cf837cba397b5..88aa46ce33617 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -386,11 +386,15 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode { $cachedPath = $this->pathByIdCache->get($this->user->getUID() . '::' . $id); if ($cachedPath && str_starts_with($cachedPath, $path)) { // getting the node by path is significantly cheaper than finding it by id - $node = $this->get($cachedPath); - // by validating that the cached path still has the requested fileid we can work around the need to invalidate the cached path - // if the cached path is invalid or a different file now we fall back to the uncached logic - if ($node && $node->getId() === $id) { - return $node; + try { + $node = $this->get($cachedPath); + // by validating that the cached path still has the requested fileid we can work around the need to invalidate the cached path + // if the cached path is invalid or a different file now we fall back to the uncached logic + if ($node && $node->getId() === $id) { + return $node; + } + } catch (NotFoundException|NotPermittedException) { + // The file may be moved but the old path still in cache } } }