From 0636697289b7ad50bfaa33c93ce4593543d435b5 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 2 Sep 2018 17:44:19 +0200 Subject: [PATCH] EntryRepository: refactor getBuilderForUntaggedByUser Improve SQL performance by replacing size(e.tags) with a left join and a null condition Move the QueryBuilder logic into getRawBuilderForUntaggedByUser Signed-off-by: Kevin Decherf --- .../CoreBundle/Repository/EntryRepository.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 749d2338..a31f97b5 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -102,7 +102,7 @@ class EntryRepository extends EntityRepository } /** - * Retrieves untagged entries for a user. + * Retrieve a sorted list of untagged entries for a user. * * @param int $userId * @@ -111,8 +111,21 @@ class EntryRepository extends EntityRepository public function getBuilderForUntaggedByUser($userId) { return $this - ->getSortedQueryBuilderByUser($userId) - ->andWhere('size(e.tags) = 0'); + ->sortQueryBuilder($this->getRawBuilderForUntaggedByUser($userId)); + } + + /** + * Retrieve untagged entries for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getRawBuilderForUntaggedByUser($userId) + { + return $this->getQueryBuilderByUser($userId) + ->leftJoin('e.tags', 't') + ->andWhere('t.id is null'); } /** -- 2.41.0