X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=e76878d49d6e7cc5bb06c0f2a1d8227ef2bec4bc;hb=10d85dbae39ae22cd55f4363fda1ef065c83a109;hp=afeb985b30c272c9b9f76d84540b15eaf230f172;hpb=06c190887fd38c314db8d240ab2e46f5777ed59e;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index afeb985b..e76878d4 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -3,43 +3,37 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; -use Pagerfanta\Adapter\DoctrineORMAdapter; -use Pagerfanta\Pagerfanta; class TagRepository extends EntityRepository { /** - * Return only the QueryBuilder to retrieve all tags for a given user. + * Count all tags per user. * * @param int $userId + * @param int $cacheLifeTime Duration of the cache for this query * - * @return QueryBuilder + * @return int */ - private function getQbForAllTags($userId) + public function countAllTags($userId, $cacheLifeTime = null) { - return $this->createQueryBuilder('t') + $query = $this->createQueryBuilder('t') + ->select('t.slug') ->leftJoin('t.entries', 'e') - ->where('e.user = :userId')->setParameter('userId', $userId); - } + ->where('e.user = :userId')->setParameter('userId', $userId) + ->groupBy('t.slug') + ->getQuery(); - /** - * Find Tags and return a Pager. - * - * @param int $userId - * - * @return Pagerfanta - */ - public function findTags($userId) - { - $qb = $this->getQbForAllTags($userId); - - $pagerAdapter = new DoctrineORMAdapter($qb); + if (null !== $cacheLifeTime) { + $query->useQueryCache(true); + $query->useResultCache(true); + $query->setResultCacheLifetime($cacheLifeTime); + } - return new Pagerfanta($pagerAdapter); + return count($query->getArrayResult()); } /** - * Find Tags. + * Find all tags per user. * * @param int $userId * @@ -47,9 +41,15 @@ class TagRepository extends EntityRepository */ public function findAllTags($userId) { - return $this->getQbForAllTags($userId) + return $this->createQueryBuilder('t') + ->select('t.slug', 't.label', 't.id') + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId')->setParameter('userId', $userId) + ->groupBy('t.slug') + ->addGroupBy('t.label') + ->addGroupBy('t.id') ->getQuery() - ->getResult(); + ->getArrayResult(); } /**