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 <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2018-09-02 17:44:19 +02:00
parent b7c5fda512
commit 0636697289

View file

@ -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 * @param int $userId
* *
@ -111,8 +111,21 @@ class EntryRepository extends EntityRepository
public function getBuilderForUntaggedByUser($userId) public function getBuilderForUntaggedByUser($userId)
{ {
return $this return $this
->getSortedQueryBuilderByUser($userId) ->sortQueryBuilder($this->getRawBuilderForUntaggedByUser($userId));
->andWhere('size(e.tags) = 0'); }
/**
* 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');
} }
/** /**