aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-09-01 20:20:12 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-09-01 20:20:12 +0200
commit0b0233b1ec8208be47c76856a4e317673927b21e (patch)
tree9715b84d02b9e6858bf10686fa0fd45813466d22 /src
parentf997ae6afb72e6a2f3d8ff8bd30a354e35696410 (diff)
downloadwallabag-0b0233b1ec8208be47c76856a4e317673927b21e.tar.gz
wallabag-0b0233b1ec8208be47c76856a4e317673927b21e.tar.zst
wallabag-0b0233b1ec8208be47c76856a4e317673927b21e.zip
Enable cache for queries
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php17
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php27
2 files changed, 36 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index e9351d85..86bce545 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -3,6 +3,7 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Query;
6use Pagerfanta\Adapter\DoctrineORMAdapter; 7use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta; 8use Pagerfanta\Pagerfanta;
8use Wallabag\CoreBundle\Entity\Tag; 9use Wallabag\CoreBundle\Entity\Tag;
@@ -279,4 +280,20 @@ class EntryRepository extends EntityRepository
279 280
280 return $qb->getQuery()->getSingleScalarResult(); 281 return $qb->getQuery()->getSingleScalarResult();
281 } 282 }
283
284 /**
285 * Enable cache for a query
286 *
287 * @param Query $query
288 *
289 * @return Query
290 */
291 public function enableCache(Query $query)
292 {
293 $query->useQueryCache(true);
294 $query->useResultCache(true);
295 $query->setResultCacheLifetime(5);
296
297 return $query;
298 }
282} 299}
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
index 6e46c701..5c475d61 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
36 return array(); 36 return array();
37 } 37 }
38 38
39 $unreadEntries = $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult(); 39 $unreadEntries = $this->repository->enableCache(
40 $starredEntries = $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()->getResult(); 40 $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()
41 $archivedEntries = $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult(); 41 );
42 $allEntries = $this->repository->getBuilderForAllByUser($user->getId())->getQuery()->getResult(); 42
43 $starredEntries = $this->repository->enableCache(
44 $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()
45 );
46
47 $archivedEntries = $this->repository->enableCache(
48 $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()
49 );
50
51 $allEntries = $this->repository->enableCache(
52 $this->repository->getBuilderForAllByUser($user->getId())->getQuery()
53 );
43 54
44 return array( 55 return array(
45 'unreadEntries' => count($unreadEntries), 56 'unreadEntries' => count($unreadEntries->getResult()),
46 'starredEntries' => count($starredEntries), 57 'starredEntries' => count($starredEntries->getResult()),
47 'archivedEntries' => count($archivedEntries), 58 'archivedEntries' => count($archivedEntries->getResult()),
48 'allEntries' => count($allEntries), 59 'allEntries' => count($allEntries->getResult()),
49 ); 60 );
50 } 61 }
51 62