]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: cannot apply limit+offset on multi-tag-search 37969/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 27 Jun 2023 20:49:08 +0000 (22:49 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 27 Jun 2023 21:06:39 +0000 (23:06 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/dav/lib/Connector/Sabre/FilesReportPlugin.php

index 6122ba1bfe717314edd1be38b1f9166625cef3de..4b26d83777925f5019e8572c4375033b899c0971 100644 (file)
@@ -338,9 +338,15 @@ class FilesReportPlugin extends ServerPlugin {
                // exposed in API yet
                if (!empty($systemTagIds)) {
                        $tags = $this->tagManager->getTagsByIds($systemTagIds, $this->userSession->getUser());
+
+                       // For we run DB queries per tag and require intersection, we cannot apply limit and offset for DB queries on multi tag search.
+                       $oneTagSearch = count($tags) === 1;
+                       $dbLimit = $oneTagSearch ? $limit ?? 0 : 0;
+                       $dbOffset = $oneTagSearch ? $offset ?? 0 : 0;
+
                        foreach ($tags as $tag) {
                                $tagName = $tag->getName();
-                               $tmpNodes = $this->userFolder->searchBySystemTag($tagName, $this->userSession->getUser()->getUID(), $limit ?? 0, $offset ?? 0);
+                               $tmpNodes = $this->userFolder->searchBySystemTag($tagName, $this->userSession->getUser()->getUID(), $dbLimit, $dbOffset);
                                if (count($nodes) === 0) {
                                        $nodes = $tmpNodes;
                                } else {
@@ -353,6 +359,10 @@ class FilesReportPlugin extends ServerPlugin {
                                        return $nodes;
                                }
                        }
+
+                       if (!$oneTagSearch && ($limit !== null || $offset !== null)) {
+                               $nodes = array_slice($nodes, $offset, $limit);
+                       }
                }
 
                return $nodes;