aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Twig
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-03 18:11:07 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-03 18:11:07 +0200
commit543da3e0b7592b1a00a7c5baec1554460609d63f (patch)
treeb7e3ad3bbd69ff99e2d051a4381e2854706fad57 /src/Wallabag/CoreBundle/Twig
parent8f8654913ce82be12219a37a24630066bbe950c2 (diff)
downloadwallabag-543da3e0b7592b1a00a7c5baec1554460609d63f.tar.gz
wallabag-543da3e0b7592b1a00a7c5baec1554460609d63f.tar.zst
wallabag-543da3e0b7592b1a00a7c5baec1554460609d63f.zip
Instead of selecting the whole data, just count it
Instead of performing a complex select (to retrieve all data for entry, etc...) just select the counter and retrieve it. Down from ~50ms to ~30ms on the unread page (with 500 items)
Diffstat (limited to 'src/Wallabag/CoreBundle/Twig')
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
index 5c475d61..93640dc6 100644
--- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
+++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
@@ -33,31 +33,31 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
33 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; 33 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
34 34
35 if (null === $user || !is_object($user)) { 35 if (null === $user || !is_object($user)) {
36 return array(); 36 return [];
37 } 37 }
38 38
39 $unreadEntries = $this->repository->enableCache( 39 $unreadEntries = $this->repository->enableCache(
40 $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery() 40 $this->repository->getBuilderForUnreadByUser($user->getId())->select('COUNT(e.id)')->getQuery()
41 ); 41 );
42 42
43 $starredEntries = $this->repository->enableCache( 43 $starredEntries = $this->repository->enableCache(
44 $this->repository->getBuilderForStarredByUser($user->getId())->getQuery() 44 $this->repository->getBuilderForStarredByUser($user->getId())->select('COUNT(e.id)')->getQuery()
45 ); 45 );
46 46
47 $archivedEntries = $this->repository->enableCache( 47 $archivedEntries = $this->repository->enableCache(
48 $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery() 48 $this->repository->getBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)')->getQuery()
49 ); 49 );
50 50
51 $allEntries = $this->repository->enableCache( 51 $allEntries = $this->repository->enableCache(
52 $this->repository->getBuilderForAllByUser($user->getId())->getQuery() 52 $this->repository->getBuilderForAllByUser($user->getId())->select('COUNT(e.id)')->getQuery()
53 ); 53 );
54 54
55 return array( 55 return [
56 'unreadEntries' => count($unreadEntries->getResult()), 56 'unreadEntries' => $unreadEntries->getSingleScalarResult(),
57 'starredEntries' => count($starredEntries->getResult()), 57 'starredEntries' => $starredEntries->getSingleScalarResult(),
58 'archivedEntries' => count($archivedEntries->getResult()), 58 'archivedEntries' => $archivedEntries->getSingleScalarResult(),
59 'allEntries' => count($allEntries->getResult()), 59 'allEntries' => $allEntries->getSingleScalarResult(),
60 ); 60 ];
61 } 61 }
62 62
63 public function getName() 63 public function getName()