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:
Jeremy Benoist
2016-10-09 18:41:19 +02:00
parent b4fcd60e7f
commit 28bb48905a
13 changed files with 92 additions and 45 deletions

View File

@ -86,10 +86,25 @@ class TagController extends Controller
{
$tags = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->findAllTagsWithEntries($this->getUser()->getId());
->findAllTags($this->getUser()->getId());
$flatTags = [];
foreach ($tags as $key => $tag) {
$nbEntries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']);
$flatTags[] = [
'id' => $tag['id'],
'label' => $tag['label'],
'slug' => $tag['slug'],
'nbEntries' => $nbEntries,
];
}
return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
'tags' => $tags,
'tags' => $flatTags,
]);
}