From 28bb48905a2104adad65508f51737f987dc1ad4c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:41:19 +0200 Subject: Optimize the way tag list is rendered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of retrieve all informations about entries of a tag to just count them, we’ll count them before with a fastest query. Also change the layout of the tag list in material design --- .../CoreBundle/Repository/EntryRepository.php | 20 ++++++++++++++++++++ src/Wallabag/CoreBundle/Repository/TagRepository.php | 10 +++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Repository') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 75127b7d..cd2b47b9 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -309,4 +309,24 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getSingleScalarResult(); } + + /** + * Count all entries for a tag and a user. + * + * @param int $userId + * @param int $tagId + * + * @return int + */ + public function countAllEntriesByUserIdAndTagId($userId, $tagId) + { + $qb = $this->createQueryBuilder('e') + ->select('count(e.id)') + ->leftJoin('e.tags', 't') + ->where('e.user=:userId')->setParameter('userId', $userId) + ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId) + ; + + return $qb->getQuery()->getSingleScalarResult(); + } } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 9d127da7..e76878d4 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -33,19 +33,23 @@ class TagRepository extends EntityRepository } /** - * Find all tags with associated entries per user. + * Find all tags per user. * * @param int $userId * * @return array */ - public function findAllTagsWithEntries($userId) + public function findAllTags($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(); } /** -- cgit v1.2.3