diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index e9351d85e..86bce545e 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Query; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; use Wallabag\CoreBundle\Entity\Tag; @@ -279,4 +280,20 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getSingleScalarResult(); } + + /** + * Enable cache for a query + * + * @param Query $query + * + * @return Query + */ + public function enableCache(Query $query) + { + $query->useQueryCache(true); + $query->useResultCache(true); + $query->setResultCacheLifetime(5); + + return $query; + } } diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 6e46c7018..5c475d614 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -36,16 +36,27 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa return array(); } - $unreadEntries = $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult(); - $starredEntries = $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()->getResult(); - $archivedEntries = $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult(); - $allEntries = $this->repository->getBuilderForAllByUser($user->getId())->getQuery()->getResult(); + $unreadEntries = $this->repository->enableCache( + $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery() + ); + + $starredEntries = $this->repository->enableCache( + $this->repository->getBuilderForStarredByUser($user->getId())->getQuery() + ); + + $archivedEntries = $this->repository->enableCache( + $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery() + ); + + $allEntries = $this->repository->enableCache( + $this->repository->getBuilderForAllByUser($user->getId())->getQuery() + ); return array( - 'unreadEntries' => count($unreadEntries), - 'starredEntries' => count($starredEntries), - 'archivedEntries' => count($archivedEntries), - 'allEntries' => count($allEntries), + 'unreadEntries' => count($unreadEntries->getResult()), + 'starredEntries' => count($starredEntries->getResult()), + 'archivedEntries' => count($archivedEntries->getResult()), + 'allEntries' => count($allEntries->getResult()), ); }