X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=inline;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=9d127da7143b588e4b600088502ffd61c7dd654d;hb=db5541e7a1e7131d62b4df23fa6eadd0c542b256;hp=abf915fe5c7f23629af5b746530dc6d6c868d792;hpb=97c8eb3c2398d0aaf06155de5e0828e4020cb5d4;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index abf915fe..9d127da7 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -7,13 +7,39 @@ use Doctrine\ORM\EntityRepository; class TagRepository extends EntityRepository { /** - * Find Tags. + * Count all tags per user. + * + * @param int $userId + * @param int $cacheLifeTime Duration of the cache for this query + * + * @return int + */ + public function countAllTags($userId, $cacheLifeTime = null) + { + $query = $this->createQueryBuilder('t') + ->select('t.slug') + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId')->setParameter('userId', $userId) + ->groupBy('t.slug') + ->getQuery(); + + if (null !== $cacheLifeTime) { + $query->useQueryCache(true); + $query->useResultCache(true); + $query->setResultCacheLifetime($cacheLifeTime); + } + + return count($query->getArrayResult()); + } + + /** + * Find all tags with associated entries per user. * * @param int $userId * * @return array */ - public function findAllTags($userId) + public function findAllTagsWithEntries($userId) { return $this->createQueryBuilder('t') ->leftJoin('t.entries', 'e')