Skip to content

Commit b6d9e26

Browse files
CarlSchwansilverkszlo
authored andcommitted
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 <carlschwan@kde.org>
1 parent c48b7f1 commit b6d9e26

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

lib/DAV/WorkspacePlugin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Exception;
1212
use OC\Files\Node\File;
13-
use OCA\DAV\Connector\Sabre\Directory;
1413
use OCA\DAV\Files\FilesHome;
1514
use OCA\Text\Service\ConfigService;
1615
use OCA\Text\Service\WorkspaceService;
@@ -64,7 +63,7 @@ public function propFind(PropFind $propFind, INode $node) {
6463
return;
6564
}
6665

67-
if (!$node instanceof Directory && !$node instanceof FilesHome) {
66+
if (!$node instanceof FilesHome) {
6867
return;
6968
}
7069

lib/Service/WorkspaceService.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
use OCP\Files\File;
1212
use OCP\Files\Folder;
13-
use OCP\Files\NotFoundException;
14-
use OCP\Files\StorageInvalidException;
1513
use OCP\IL10N;
1614

1715
class WorkspaceService {
@@ -28,17 +26,13 @@ public function __construct(IL10N $l10n) {
2826
}
2927

3028
public function getFile(Folder $folder): ?File {
31-
foreach ($this->getSupportedFilenames() as $filename) {
32-
try {
33-
$exists = $folder->getStorage()->getCache()->get($folder->getInternalPath() . '/' . $filename);
34-
if ($exists) {
35-
$file = $folder->get($filename);
36-
if ($file instanceof File) {
37-
return $file;
38-
}
29+
$content = $folder->getStorage()->getCache()->getFolderContents($folder->getInternalPath() . '/', 'text/markdown');
30+
foreach ($content as $file) {
31+
if (in_array($file->getName(), $this->getSupportedFilenames(), true)) {
32+
$file = $folder->get($file->getPath());
33+
if ($file instanceof File) {
34+
return $file;
3935
}
40-
} catch (NotFoundException|StorageInvalidException) {
41-
continue;
4236
}
4337
}
4438
return null;

0 commit comments

Comments
 (0)