From 452362c17a25a3b37b4d12d170654802b6f9ea18 Mon Sep 17 00:00:00 2001 From: Simounet Date: Thu, 31 Aug 2023 11:32:20 +0200 Subject: [PATCH 1/3] Untagged entries number removed from the filter's sidebar --- src/Wallabag/CoreBundle/Controller/EntryController.php | 4 ---- .../CoreBundle/Resources/views/Entry/entries.html.twig | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 655217c95..ca9ff56f3 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -675,9 +675,6 @@ class EntryController extends AbstractController } } - $nbEntriesUntagged = $this->entryRepository - ->countUntaggedEntriesByUser($this->getUser()->getId()); - return $this->render( '@WallabagCore/Entry/entries.html.twig', [ 'form' => $form->createView(), @@ -685,7 +682,6 @@ class EntryController extends AbstractController 'currentPage' => $page, 'searchTerm' => $searchTerm, 'isFiltered' => $form->isSubmitted(), - 'nbEntriesUntagged' => $nbEntriesUntagged, ] ); } diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig index f3f1488a8..7f1f2592d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig @@ -118,9 +118,9 @@

{{ 'entry.filters.title'|trans }}

- {% if current_route != 'untagged' and nbEntriesUntagged != 0 %} + {% if current_route != 'untagged' %} {% endif %} From 18615738c08309b655276ebb053599660f30185c Mon Sep 17 00:00:00 2001 From: Simounet Date: Thu, 31 Aug 2023 11:40:21 +0200 Subject: [PATCH 2/3] Title removed from footer's stats element --- src/Wallabag/CoreBundle/Resources/views/layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Resources/views/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/layout.html.twig index f1565f17b..10d92133e 100644 --- a/src/Wallabag/CoreBundle/Resources/views/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/layout.html.twig @@ -168,7 +168,7 @@
-
From 137c8ab756538e979547c1339782dc1b647069d0 Mon Sep 17 00:00:00 2001 From: Simounet Date: Thu, 31 Aug 2023 12:13:15 +0200 Subject: [PATCH 3/3] Count queries simplified --- .../CoreBundle/Repository/EntryRepository.php | 91 +++++++++++++++++++ .../CoreBundle/Twig/WallabagExtension.php | 24 ++--- 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 9dded5e57..3e0b4effd 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -37,6 +37,20 @@ class EntryRepository extends ServiceEntityRepository ; } + /** + * Retrieves all entries count for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getCountBuilderForAllByUser($userId) + { + return $this + ->getQueryBuilderByUser($userId) + ; + } + /** * Retrieves unread entries for a user. * @@ -52,6 +66,21 @@ class EntryRepository extends ServiceEntityRepository ; } + /** + * Retrieves unread entries count for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getCountBuilderForUnreadByUser($userId) + { + return $this + ->getQueryBuilderByUser($userId) + ->andWhere('e.isArchived = false') + ; + } + /** * Retrieves entries with the same domain. * @@ -94,6 +123,21 @@ class EntryRepository extends ServiceEntityRepository ; } + /** + * Retrieves read entries count for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getCountBuilderForArchiveByUser($userId) + { + return $this + ->getQueryBuilderByUser($userId) + ->andWhere('e.isArchived = true') + ; + } + /** * Retrieves starred entries for a user. * @@ -109,6 +153,21 @@ class EntryRepository extends ServiceEntityRepository ; } + /** + * Retrieves starred entries count for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getCountBuilderForStarredByUser($userId) + { + return $this + ->getQueryBuilderByUser($userId) + ->andWhere('e.isStarred = true') + ; + } + /** * Retrieves entries filtered with a search term for a user. * @@ -167,6 +226,21 @@ class EntryRepository extends ServiceEntityRepository ; } + /** + * Retrieve entries with annotations count for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getCountBuilderForAnnotationsByUser($userId) + { + return $this + ->getQueryBuilderByUser($userId) + ->innerJoin('e.annotations', 'a') + ; + } + /** * Retrieve untagged entries for a user. * @@ -563,6 +637,23 @@ class EntryRepository extends ServiceEntityRepository return $qb->getQuery()->getArrayResult(); } + /** + * @param int $userId + * + * @return array + */ + public function findEmptyEntriesIdByUserId($userId = null) + { + $qb = $this->createQueryBuilder('e') + ->select('e.id'); + + if (null !== $userId) { + $qb->where('e.user = :userid AND e.content IS NULL')->setParameter(':userid', $userId); + } + + return $qb->getQuery()->getArrayResult(); + } + /** * Find all entries by url and owner. * diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index e94bf3603..a31cacf0e 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -88,35 +88,32 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface switch ($type) { case 'starred': - $qb = $this->entryRepository->getBuilderForStarredByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForStarredByUser($user->getId()); break; case 'archive': - $qb = $this->entryRepository->getBuilderForArchiveByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForArchiveByUser($user->getId()); break; case 'unread': - $qb = $this->entryRepository->getBuilderForUnreadByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForUnreadByUser($user->getId()); break; case 'annotated': - $qb = $this->entryRepository->getBuilderForAnnotationsByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForAnnotationsByUser($user->getId()); break; case 'all': - $qb = $this->entryRepository->getBuilderForAllByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId()); break; default: throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); } - // THANKS to PostgreSQL we CAN'T make a DEAD SIMPLE count(e.id) - // ERROR: column "e0_.id" must appear in the GROUP BY clause or be used in an aggregate function $query = $qb - ->select('e.id') - ->groupBy('e.id') + ->select('COUNT(e.id)') ->getQuery(); $query->useQueryCache(true); $query->enableResultCache($this->lifeTime); - return \count($query->getArrayResult()); + return $query->getSingleScalarResult(); } /** @@ -148,15 +145,14 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface return 0; } - $query = $this->entryRepository->getBuilderForArchiveByUser($user->getId()) - ->select('e.id') - ->groupBy('e.id') + $query = $this->entryRepository->getCountBuilderForArchiveByUser($user->getId()) + ->select('COUNT(e.id)') ->getQuery(); $query->useQueryCache(true); $query->enableResultCache($this->lifeTime); - $nbArchives = \count($query->getArrayResult()); + $nbArchives = $query->getSingleScalarResult(); $interval = $user->getCreatedAt()->diff(new \DateTime('now')); $nbDays = (int) $interval->format('%a') ?: 1;