diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-11 21:45:43 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-22 13:13:07 +0200 |
commit | b0de88f75dead50385e80e3897dc3913a971b91e (patch) | |
tree | 41a8b4977271e4b7c9cf68ec3747e5993f791182 /src/Wallabag/CoreBundle/Repository | |
parent | 8c61fd12b1df50d481e9f82c39521cca7b8ad060 (diff) | |
download | wallabag-b0de88f75dead50385e80e3897dc3913a971b91e.tar.gz wallabag-b0de88f75dead50385e80e3897dc3913a971b91e.tar.zst wallabag-b0de88f75dead50385e80e3897dc3913a971b91e.zip |
Use statements & update translation
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 33 |
2 files changed, 14 insertions, 22 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 5df5eff5..14616d88 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -339,7 +339,8 @@ class EntryRepository extends EntityRepository | |||
339 | public function removeAllByUserId($userId) | 339 | public function removeAllByUserId($userId) |
340 | { | 340 | { |
341 | $this->getEntityManager() | 341 | $this->getEntityManager() |
342 | ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = '.$userId) | 342 | ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId') |
343 | ->setParameter('userId', $userId) | ||
343 | ->execute(); | 344 | ->execute(); |
344 | } | 345 | } |
345 | } | 346 | } |
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 | /** |