X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=2182df254315b9341448f01ba7191bfc50eed7e1;hb=d83d25dadec2c38460a32d96f5d2903426fec9d3;hp=9d127da7143b588e4b600088502ffd61c7dd654d;hpb=7e98ad962680fac17b3b90ae34b9c6e5afe7636f;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 9d127da7..2182df25 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -33,19 +33,32 @@ class TagRepository extends EntityRepository } /** - * Find all tags with associated entries per user. + * 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 * * @return array */ - public function findAllTagsWithEntries($userId) + public function findAllTags($userId) { - return $this->createQueryBuilder('t') + $ids = $this->createQueryBuilder('t') + ->select('t.id') ->leftJoin('t.entries', 'e') ->where('e.user = :userId')->setParameter('userId', $userId) + ->groupBy('t.id') + ->orderBy('t.slug') ->getQuery() - ->getResult(); + ->getArrayResult(); + + $tags = []; + foreach ($ids as $id) { + $tags[] = $this->find($id); + } + + return $tags; } /**