]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/TagRepository.php
Use statements & update translation
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
index 69661b128374a2a905e7b7b77a1f4b3fb39a71b3..81445989b71c97fc06a13e22f8aaada1b81d871d 100644 (file)
@@ -34,6 +34,9 @@ class TagRepository extends EntityRepository
 
     /**
      * Find all tags per user.
+     * Instead of just left joined on the Entry table, we select only id and group by id to avoid tag multiplication in results.
+     * Once we have all tags id, we can safely request them one by one.
+     * This'll still be fastest than the previous query.
      *
      * @param int $userId
      *
@@ -41,32 +44,20 @@ class TagRepository extends EntityRepository
      */
     public function findAllTags($userId)
     {
-        return $this->createQueryBuilder('t')
-            ->select('t.slug', 't.label', 't.id')
+        $ids = $this->createQueryBuilder('t')
+            ->select('t.id')
             ->leftJoin('t.entries', 'e')
             ->where('e.user = :userId')->setParameter('userId', $userId)
-            ->groupBy('t.slug')
-            ->addGroupBy('t.label')
-            ->addGroupBy('t.id')
+            ->groupBy('t.id')
             ->getQuery()
             ->getArrayResult();
-    }
 
-    /**
-     * Find all tags.
-     *
-     * @param int $userId
-     *
-     * @return array
-     */
-    public function findAllTags($userId)
-    {
-        return $this->createQueryBuilder('t')
-            ->select('t')
-            ->leftJoin('t.entries', 'e')
-            ->where('e.user = :userId')->setParameter('userId', $userId)
-            ->getQuery()
-            ->getResult();
+        $tags = [];
+        foreach ($ids as $id) {
+            $tags[] = $this->find($id);
+        }
+
+        return $tags;
     }
 
     /**