From faa86e06ba3032fdb98f3c0f79c72e8581d3c96f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 11:21:13 +0200 Subject: Fix tags count in menu Move enable cache for Tag in the Entity because function `find*` should return result and not a Query --- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 28 ++++------------------ 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'src/Wallabag/CoreBundle/Twig') diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 3780b13e..0a6896c9 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -85,10 +85,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa ->groupBy('e.id') ->getQuery(); - $data = $this->enableCache($query) - ->getArrayResult(); + $query->useQueryCache(true); + $query->useResultCache(true); + $query->setResultCacheLifetime($this->lifeTime); - return count($data); + return count($query->getArrayResult()); } /** @@ -104,30 +105,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa return 0; } - $qb = $this->tagRepository->findAllTags($user->getId()); - - $data = $this->enableCache($qb->getQuery()) - ->getArrayResult(); + $data = $this->tagRepository->findAllTags($user->getId()); return count($data); } - /** - * Enable cache for a query. - * - * @param Query $query - * - * @return Query - */ - private function enableCache(Query $query) - { - $query->useQueryCache(true); - $query->useResultCache(true); - $query->setResultCacheLifetime($this->lifeTime); - - return $query; - } - public function getName() { return 'wallabag_extension'; -- cgit v1.2.3 From 82fc3290d4fec45ede270e2c1ad2079fe3020adc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 12:03:12 +0200 Subject: CS --- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Twig') diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 0a6896c9..45dc591d 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Twig; -use Doctrine\ORM\Query; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Repository\EntryRepository; use Wallabag\CoreBundle\Repository\TagRepository; -- cgit v1.2.3 From 289875836a09944f5993d33753042abfef13809e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 12:23:44 +0200 Subject: Fix tag count for PostgreSQL --- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Twig') diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 45dc591d..fb4c7412 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -104,9 +104,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa return 0; } - $data = $this->tagRepository->findAllTags($user->getId()); - - return count($data); + return $this->tagRepository->countAllTags($user->getId()); } public function getName() -- cgit v1.2.3