Skip to content

Commit 49c1bf2

Browse files
committed
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 df460f8 commit 49c1bf2

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

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: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
use OCP\Files\File;
1212
use OCP\Files\Folder;
13-
use OCP\Files\NotFoundException;
14-
use OCP\Files\NotPermittedException;
15-
use OCP\Files\StorageInvalidException;
1613
use OCP\IL10N;
1714

1815
class WorkspaceService {
@@ -28,14 +25,13 @@ public function __construct(
2825
}
2926

3027
public function getFile(Folder $folder): ?File {
31-
foreach ($this->getSupportedFilenames() as $filename) {
32-
try {
33-
$file = $folder->get($filename);
28+
$content = $folder->getStorage()->getCache()->getFolderContents($folder->getInternalPath() . '/', 'text/markdown');
29+
foreach ($content as $file) {
30+
if (in_array($file->getName(), $this->getSupportedFilenames(), true)) {
31+
$file = $folder->get($file->getPath());
3432
if ($file instanceof File) {
3533
return $file;
3634
}
37-
} catch (NotFoundException|NotPermittedException|StorageInvalidException) {
38-
continue;
3935
}
4036
}
4137
return null;

0 commit comments

Comments
 (0)