From b6d9e26200a9f86ff3abb21dd1d70f2e8b8424a5 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 29 Jan 2026 15:45:00 +0100 Subject: [PATCH] perf: Get readme from folder Directly get all markdown files from parent directory in one SQL query and then filter on it by name. Signed-off-by: Carl Schwan --- lib/DAV/WorkspacePlugin.php | 3 +-- lib/Service/WorkspaceService.php | 18 ++++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/DAV/WorkspacePlugin.php b/lib/DAV/WorkspacePlugin.php index fa4bc5568a7..a3005852ea8 100644 --- a/lib/DAV/WorkspacePlugin.php +++ b/lib/DAV/WorkspacePlugin.php @@ -10,7 +10,6 @@ use Exception; use OC\Files\Node\File; -use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Files\FilesHome; use OCA\Text\Service\ConfigService; use OCA\Text\Service\WorkspaceService; @@ -64,7 +63,7 @@ public function propFind(PropFind $propFind, INode $node) { return; } - if (!$node instanceof Directory && !$node instanceof FilesHome) { + if (!$node instanceof FilesHome) { return; } diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index 40e4d439821..89fc5490813 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -10,8 +10,6 @@ use OCP\Files\File; use OCP\Files\Folder; -use OCP\Files\NotFoundException; -use OCP\Files\StorageInvalidException; use OCP\IL10N; class WorkspaceService { @@ -28,17 +26,13 @@ public function __construct(IL10N $l10n) { } public function getFile(Folder $folder): ?File { - foreach ($this->getSupportedFilenames() as $filename) { - try { - $exists = $folder->getStorage()->getCache()->get($folder->getInternalPath() . '/' . $filename); - if ($exists) { - $file = $folder->get($filename); - if ($file instanceof File) { - return $file; - } + $content = $folder->getStorage()->getCache()->getFolderContents($folder->getInternalPath() . '/', 'text/markdown'); + foreach ($content as $file) { + if (in_array($file->getName(), $this->getSupportedFilenames(), true)) { + $file = $folder->get($file->getPath()); + if ($file instanceof File) { + return $file; } - } catch (NotFoundException|StorageInvalidException) { - continue; } } return null;