forked from wallabag/wallabag
Optimize the way tag list is rendered
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
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user