aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/TagRepository.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-11 21:45:43 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-22 13:13:07 +0200
commitb0de88f75dead50385e80e3897dc3913a971b91e (patch)
tree41a8b4977271e4b7c9cf68ec3747e5993f791182 /src/Wallabag/CoreBundle/Repository/TagRepository.php
parent8c61fd12b1df50d481e9f82c39521cca7b8ad060 (diff)
downloadwallabag-b0de88f75dead50385e80e3897dc3913a971b91e.tar.gz
wallabag-b0de88f75dead50385e80e3897dc3913a971b91e.tar.zst
wallabag-b0de88f75dead50385e80e3897dc3913a971b91e.zip
Use statements & update translation
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/TagRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index 69661b12..81445989 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -34,6 +34,9 @@ class TagRepository extends EntityRepository
34 34
35 /** 35 /**
36 * Find all tags per user. 36 * Find all tags per user.
37 * Instead of just left joined on the Entry table, we select only id and group by id to avoid tag multiplication in results.
38 * Once we have all tags id, we can safely request them one by one.
39 * This'll still be fastest than the previous query.
37 * 40 *
38 * @param int $userId 41 * @param int $userId
39 * 42 *
@@ -41,32 +44,20 @@ class TagRepository extends EntityRepository
41 */ 44 */
42 public function findAllTags($userId) 45 public function findAllTags($userId)
43 { 46 {
44 return $this->createQueryBuilder('t') 47 $ids = $this->createQueryBuilder('t')
45 ->select('t.slug', 't.label', 't.id') 48 ->select('t.id')
46 ->leftJoin('t.entries', 'e') 49 ->leftJoin('t.entries', 'e')
47 ->where('e.user = :userId')->setParameter('userId', $userId) 50 ->where('e.user = :userId')->setParameter('userId', $userId)
48 ->groupBy('t.slug') 51 ->groupBy('t.id')
49 ->addGroupBy('t.label')
50 ->addGroupBy('t.id')
51 ->getQuery() 52 ->getQuery()
52 ->getArrayResult(); 53 ->getArrayResult();
53 }
54 54
55 /** 55 $tags = [];
56 * Find all tags. 56 foreach ($ids as $id) {
57 * 57 $tags[] = $this->find($id);
58 * @param int $userId 58 }
59 * 59
60 * @return array 60 return $tags;
61 */
62 public function findAllTags($userId)
63 {
64 return $this->createQueryBuilder('t')
65 ->select('t')
66 ->leftJoin('t.entries', 'e')
67 ->where('e.user = :userId')->setParameter('userId', $userId)
68 ->getQuery()
69 ->getResult();
70 } 61 }
71 62
72 /** 63 /**