mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-20 19:52:09 +00:00
Reduce number of queries on tag list
This commit is contained in:
parent
f11a3cf21c
commit
935e9fffb4
3 changed files with 23 additions and 39 deletions
|
@ -329,26 +329,6 @@ class EntryRepository extends EntityRepository
|
|||
return (int) $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 (int) $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all entries for a user id.
|
||||
* Used when a user want to reset all informations.
|
||||
|
|
|
@ -62,6 +62,27 @@ class TagRepository extends EntityRepository
|
|||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all tags (flat) per user with nb entries.
|
||||
*
|
||||
* @param int $userId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findAllFlatTagsWithNbEntries($userId)
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->select('t.id, t.label, t.slug, count(e.id) as nbEntries')
|
||||
->distinct(true)
|
||||
->leftJoin('t.entries', 'e')
|
||||
->where('e.user = :userId')
|
||||
->groupBy('t.id')
|
||||
->orderBy('t.slug')
|
||||
->setParameter('userId', $userId)
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used only in test case to get a tag for our entry.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue