diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 6c6b9574fce..48f5017cca1 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -492,6 +492,14 @@ public function getFileById(int $fileId, ?string $userId = null): File { throw new NotFoundException(); } + // We currently don't know the path nor care about which file mount it is when getting by id + // therefore we can take a shortcut on the cached node if we have edit permissions on that + $file = $userFolder->getFirstNodeById($fileId); + if ($file instanceof File && $file->getPermissions() & Constants::PERMISSION_UPDATE) { + return $file; + } + + // Ideally we'd optimize this part in the future by storing the path and getting the acutal target directly $files = $userFolder->getById($fileId); if (count($files) === 0) { throw new NotFoundException();