diff options
4 files changed, 47 insertions, 47 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index fb7c6c1f..dd17ef97 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -322,9 +322,7 @@ class WallabagRestController extends FOSRestController | |||
322 | 322 | ||
323 | $tags = $this->getDoctrine() | 323 | $tags = $this->getDoctrine() |
324 | ->getRepository('WallabagCoreBundle:Tag') | 324 | ->getRepository('WallabagCoreBundle:Tag') |
325 | ->findAllTags($this->getUser()->getId()) | 325 | ->findAllTagsWithEntries($this->getUser()->getId()); |
326 | ->getQuery() | ||
327 | ->getResult(); | ||
328 | 326 | ||
329 | $json = $this->get('serializer')->serialize($tags, 'json'); | 327 | $json = $this->get('serializer')->serialize($tags, 'json'); |
330 | 328 | ||
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index bc95a4d3..07cd3edb 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -84,16 +84,11 @@ class TagController extends Controller | |||
84 | { | 84 | { |
85 | $tags = $this->getDoctrine() | 85 | $tags = $this->getDoctrine() |
86 | ->getRepository('WallabagCoreBundle:Tag') | 86 | ->getRepository('WallabagCoreBundle:Tag') |
87 | ->findAllTags($this->getUser()->getId()) | 87 | ->findAllTagsWithEntries($this->getUser()->getId()); |
88 | ->getQuery() | 88 | |
89 | ->getResult(); | 89 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ |
90 | 90 | 'tags' => $tags, | |
91 | return $this->render( | 91 | ]); |
92 | 'WallabagCoreBundle:Tag:tags.html.twig', | ||
93 | [ | ||
94 | 'tags' => $tags, | ||
95 | ] | ||
96 | ); | ||
97 | } | 92 | } |
98 | 93 | ||
99 | /** | 94 | /** |
@@ -127,13 +122,10 @@ class TagController extends Controller | |||
127 | } | 122 | } |
128 | } | 123 | } |
129 | 124 | ||
130 | return $this->render( | 125 | return $this->render('WallabagCoreBundle:Entry:entries.html.twig',[ |
131 | 'WallabagCoreBundle:Entry:entries.html.twig', | 126 | 'form' => null, |
132 | [ | 127 | 'entries' => $entries, |
133 | 'form' => null, | 128 | 'currentPage' => $page, |
134 | 'entries' => $entries, | 129 | ]); |
135 | 'currentPage' => $page, | ||
136 | ] | ||
137 | ); | ||
138 | } | 130 | } |
139 | } | 131 | } |
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 41f61607..f5c4ea6a 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -7,17 +7,45 @@ use Doctrine\ORM\EntityRepository; | |||
7 | class TagRepository extends EntityRepository | 7 | class TagRepository extends EntityRepository |
8 | { | 8 | { |
9 | /** | 9 | /** |
10 | * Find Tags. | 10 | * Find all tags per user. |
11 | * | 11 | * |
12 | * @param int $userId | 12 | * @param int $userId |
13 | * @param int $cacheLifeTime Duration of the cache for this query | ||
13 | * | 14 | * |
14 | * @return array | 15 | * @return array |
15 | */ | 16 | */ |
16 | public function findAllTags($userId) | 17 | public function findAllTags($userId, $cacheLifeTime = null) |
18 | { | ||
19 | $query = $this->createQueryBuilder('t') | ||
20 | ->select('t') | ||
21 | ->leftJoin('t.entries', 'e') | ||
22 | ->where('e.user = :userId')->setParameter('userId', $userId) | ||
23 | ->groupBy('t.slug') | ||
24 | ->getQuery(); | ||
25 | |||
26 | if (null !== $cacheLifeTime) { | ||
27 | $query->useQueryCache(true); | ||
28 | $query->useResultCache(true); | ||
29 | $query->setResultCacheLifetime($cacheLifeTime); | ||
30 | } | ||
31 | |||
32 | return $query->getArrayResult(); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Find all tags with associated entries per user. | ||
37 | * | ||
38 | * @param int $userId | ||
39 | * | ||
40 | * @return array | ||
41 | */ | ||
42 | public function findAllTagsWithEntries($userId) | ||
17 | { | 43 | { |
18 | return $this->createQueryBuilder('t') | 44 | return $this->createQueryBuilder('t') |
19 | ->leftJoin('t.entries', 'e') | 45 | ->leftJoin('t.entries', 'e') |
20 | ->where('e.user = :userId')->setParameter('userId', $userId); | 46 | ->where('e.user = :userId')->setParameter('userId', $userId) |
47 | ->getQuery() | ||
48 | ->getResult(); | ||
21 | } | 49 | } |
22 | 50 | ||
23 | /** | 51 | /** |
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 | |||
85 | ->groupBy('e.id') | 85 | ->groupBy('e.id') |
86 | ->getQuery(); | 86 | ->getQuery(); |
87 | 87 | ||
88 | $data = $this->enableCache($query) | 88 | $query->useQueryCache(true); |
89 | ->getArrayResult(); | 89 | $query->useResultCache(true); |
90 | $query->setResultCacheLifetime($this->lifeTime); | ||
90 | 91 | ||
91 | return count($data); | 92 | return count($query->getArrayResult()); |
92 | } | 93 | } |
93 | 94 | ||
94 | /** | 95 | /** |
@@ -104,30 +105,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa | |||
104 | return 0; | 105 | return 0; |
105 | } | 106 | } |
106 | 107 | ||
107 | $qb = $this->tagRepository->findAllTags($user->getId()); | 108 | $data = $this->tagRepository->findAllTags($user->getId()); |
108 | |||
109 | $data = $this->enableCache($qb->getQuery()) | ||
110 | ->getArrayResult(); | ||
111 | 109 | ||
112 | return count($data); | 110 | return count($data); |
113 | } | 111 | } |
114 | 112 | ||
115 | /** | ||
116 | * Enable cache for a query. | ||
117 | * | ||
118 | * @param Query $query | ||
119 | * | ||
120 | * @return Query | ||
121 | */ | ||
122 | private function enableCache(Query $query) | ||
123 | { | ||
124 | $query->useQueryCache(true); | ||
125 | $query->useResultCache(true); | ||
126 | $query->setResultCacheLifetime($this->lifeTime); | ||
127 | |||
128 | return $query; | ||
129 | } | ||
130 | |||
131 | public function getName() | 113 | public function getName() |
132 | { | 114 | { |
133 | return 'wallabag_extension'; | 115 | return 'wallabag_extension'; |