From 543da3e0b7592b1a00a7c5baec1554460609d63f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 3 Sep 2016 18:11:07 +0200 Subject: 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) --- .../CoreBundle/Controller/DeveloperController.php | 4 ++-- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php index 1ea220e5..63386db0 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php @@ -49,7 +49,7 @@ class DeveloperController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - $this->get('translator')->trans('flashes.developer.notice.client_created', array('%name%' => $client->getName())) + $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()]) ); return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', [ @@ -81,7 +81,7 @@ class DeveloperController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - $this->get('translator')->trans('flashes.developer.notice.client_deleted', array('%name%' => $client->getName())) + $this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()]) ); return $this->redirect($this->generateUrl('developer')); 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 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; if (null === $user || !is_object($user)) { - return array(); + return []; } $unreadEntries = $this->repository->enableCache( - $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery() + $this->repository->getBuilderForUnreadByUser($user->getId())->select('COUNT(e.id)')->getQuery() ); $starredEntries = $this->repository->enableCache( - $this->repository->getBuilderForStarredByUser($user->getId())->getQuery() + $this->repository->getBuilderForStarredByUser($user->getId())->select('COUNT(e.id)')->getQuery() ); $archivedEntries = $this->repository->enableCache( - $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery() + $this->repository->getBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)')->getQuery() ); $allEntries = $this->repository->enableCache( - $this->repository->getBuilderForAllByUser($user->getId())->getQuery() + $this->repository->getBuilderForAllByUser($user->getId())->select('COUNT(e.id)')->getQuery() ); - return array( - 'unreadEntries' => count($unreadEntries->getResult()), - 'starredEntries' => count($starredEntries->getResult()), - 'archivedEntries' => count($archivedEntries->getResult()), - 'allEntries' => count($allEntries->getResult()), - ); + return [ + 'unreadEntries' => $unreadEntries->getSingleScalarResult(), + 'starredEntries' => $starredEntries->getSingleScalarResult(), + 'archivedEntries' => $archivedEntries->getSingleScalarResult(), + 'allEntries' => $allEntries->getSingleScalarResult(), + ]; } public function getName() -- cgit v1.2.3