]> source.dussan.org Git - nextcloud-server.git/commitdiff
Do not walk over the users directory, but over the list of tagged objects
authorJoas Schilling <nickvergessen@owncloud.com>
Wed, 18 Mar 2015 14:58:06 +0000 (15:58 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Mon, 23 Mar 2015 14:10:58 +0000 (15:10 +0100)
Way quicker

apps/files/service/tagservice.php
lib/private/tags.php

index fe26838552a19f1d16f793c9969601ec6aad10ef..cdd51d27f4a91b3cfa253f2ae5045051d4d18844 100644 (file)
@@ -48,7 +48,7 @@ class TagService {
         * @param string $path path
         * @param array  $tags array of tags
         * @return array list of tags
-        * @throws \OCP\NotFoundException if the file does not exist
+        * @throws \OCP\Files\NotFoundException if the file does not exist
         */
        public function updateFileTags($path, $tags) {
                $fileId = $this->homeFolder->get($path)->getId();
@@ -74,30 +74,27 @@ class TagService {
        }
 
        /**
-        * Updates the tags of the specified file path.
-        * The passed tags are absolute, which means they will
-        * replace the actual tag selection.
+        * Get all files for the given tag
         *
         * @param array $tagName tag name to filter by
         * @return FileInfo[] list of matching files
         * @throws \Exception if the tag does not exist
         */
        public function getFilesByTag($tagName) {
-               $nodes = $this->homeFolder->searchByTag(
-                       $tagName, $this->userSession->getUser()->getUId()
-               );
+               try {
+                       $fileIds = $this->tagger->getIdsForTag($tagName);
+               } catch (\Exception $e) {
+                       return [];
+               }
+
                $fileInfos = [];
-               foreach ($nodes as $node) {
-                       try {
+               foreach ($fileIds as $fileId) {
+                       $nodes = $this->homeFolder->getById((int) $fileId);
+                       foreach ($nodes as $node) {
                                /** @var \OC\Files\Node\Node $node */
                                $fileInfos[] = $node->getFileInfo();
-                       } catch (\Exception $e) {
-                               // FIXME Should notify the user, when this happens
-                               // Can not get FileInfo, maybe the connection to the external
-                               // storage is interrupted.
                        }
                }
-
                return $fileInfos;
        }
 }
index 200ec8c2771677160edff025e318969cec77672f..276da9d4b80f5daa855df076a8b51279b9d9c207 100644 (file)
@@ -34,8 +34,8 @@
 
 namespace OC;
 
-use \OC\Tagging\Tag,
-    \OC\Tagging\TagMapper;
+use \OC\Tagging\Tag;
+use \OC\Tagging\TagMapper;
 
 class Tags implements \OCP\ITags {
 
@@ -248,6 +248,7 @@ class Tags implements \OCP\ITags {
        *
        * @param string $tag Tag id or name.
        * @return array|false An array of object ids or false on error.
+       * @throws \Exception
        */
        public function getIdsForTag($tag) {
                $result = null;