diff options
author | Nicolas Hart <contact@nclshart.net> | 2017-08-06 21:58:14 +0200 |
---|---|---|
committer | Nicolas Hart <contact@nclshart.net> | 2017-08-06 23:02:32 +0200 |
commit | 935e9fffb4083f83e86c4e97a32bc2d9bccd677f (patch) | |
tree | f4607a17b6d6bf27bcc3e7f232ac692b1e3dece7 /src/Wallabag/CoreBundle/Repository/TagRepository.php | |
parent | f11a3cf21ca77f16b5dff3a6d015f2043317c596 (diff) | |
download | wallabag-935e9fffb4083f83e86c4e97a32bc2d9bccd677f.tar.gz wallabag-935e9fffb4083f83e86c4e97a32bc2d9bccd677f.tar.zst wallabag-935e9fffb4083f83e86c4e97a32bc2d9bccd677f.zip |
Reduce number of queries on tag list
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/TagRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 213283e5..5c45211f 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -63,6 +63,27 @@ class TagRepository extends EntityRepository | |||
63 | } | 63 | } |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Find all tags (flat) per user with nb entries. | ||
67 | * | ||
68 | * @param int $userId | ||
69 | * | ||
70 | * @return array | ||
71 | */ | ||
72 | public function findAllFlatTagsWithNbEntries($userId) | ||
73 | { | ||
74 | return $this->createQueryBuilder('t') | ||
75 | ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') | ||
76 | ->distinct(true) | ||
77 | ->leftJoin('t.entries', 'e') | ||
78 | ->where('e.user = :userId') | ||
79 | ->groupBy('t.id') | ||
80 | ->orderBy('t.slug') | ||
81 | ->setParameter('userId', $userId) | ||
82 | ->getQuery() | ||
83 | ->getArrayResult(); | ||
84 | } | ||
85 | |||
86 | /** | ||
66 | * Used only in test case to get a tag for our entry. | 87 | * Used only in test case to get a tag for our entry. |
67 | * | 88 | * |
68 | * @return Tag | 89 | * @return Tag |