mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-27 11:31:05 +00:00
Enable cache for queries
This commit is contained in:
parent
f997ae6afb
commit
0b0233b1ec
2 changed files with 36 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue