mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-23 05:56:18 +00:00
Fix tags count in menu
Move enable cache for Tag in the Entity because function `find*` should return result and not a Query
This commit is contained in:
parent
9d7dd6b0d2
commit
faa86e06ba
4 changed files with 46 additions and 46 deletions
|
@ -322,9 +322,7 @@ class WallabagRestController extends FOSRestController
|
||||||
|
|
||||||
$tags = $this->getDoctrine()
|
$tags = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Tag')
|
->getRepository('WallabagCoreBundle:Tag')
|
||||||
->findAllTags($this->getUser()->getId())
|
->findAllTagsWithEntries($this->getUser()->getId());
|
||||||
->getQuery()
|
|
||||||
->getResult();
|
|
||||||
|
|
||||||
$json = $this->get('serializer')->serialize($tags, 'json');
|
$json = $this->get('serializer')->serialize($tags, 'json');
|
||||||
|
|
||||||
|
|
|
@ -84,16 +84,11 @@ class TagController extends Controller
|
||||||
{
|
{
|
||||||
$tags = $this->getDoctrine()
|
$tags = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Tag')
|
->getRepository('WallabagCoreBundle:Tag')
|
||||||
->findAllTags($this->getUser()->getId())
|
->findAllTagsWithEntries($this->getUser()->getId());
|
||||||
->getQuery()
|
|
||||||
->getResult();
|
|
||||||
|
|
||||||
return $this->render(
|
return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
|
||||||
'WallabagCoreBundle:Tag:tags.html.twig',
|
'tags' => $tags,
|
||||||
[
|
]);
|
||||||
'tags' => $tags,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,13 +122,10 @@ class TagController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render(
|
return $this->render('WallabagCoreBundle:Entry:entries.html.twig',[
|
||||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
'form' => null,
|
||||||
[
|
'entries' => $entries,
|
||||||
'form' => null,
|
'currentPage' => $page,
|
||||||
'entries' => $entries,
|
]);
|
||||||
'currentPage' => $page,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,45 @@ use Doctrine\ORM\EntityRepository;
|
||||||
class TagRepository extends EntityRepository
|
class TagRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Find Tags.
|
* Find all tags per user.
|
||||||
|
*
|
||||||
|
* @param int $userId
|
||||||
|
* @param int $cacheLifeTime Duration of the cache for this query
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function findAllTags($userId, $cacheLifeTime = null)
|
||||||
|
{
|
||||||
|
$query = $this->createQueryBuilder('t')
|
||||||
|
->select('t')
|
||||||
|
->leftJoin('t.entries', 'e')
|
||||||
|
->where('e.user = :userId')->setParameter('userId', $userId)
|
||||||
|
->groupBy('t.slug')
|
||||||
|
->getQuery();
|
||||||
|
|
||||||
|
if (null !== $cacheLifeTime) {
|
||||||
|
$query->useQueryCache(true);
|
||||||
|
$query->useResultCache(true);
|
||||||
|
$query->setResultCacheLifetime($cacheLifeTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->getArrayResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all tags with associated entries per user.
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function findAllTags($userId)
|
public function findAllTagsWithEntries($userId)
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('t')
|
return $this->createQueryBuilder('t')
|
||||||
->leftJoin('t.entries', 'e')
|
->leftJoin('t.entries', 'e')
|
||||||
->where('e.user = :userId')->setParameter('userId', $userId);
|
->where('e.user = :userId')->setParameter('userId', $userId)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -85,10 +85,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
|
||||||
->groupBy('e.id')
|
->groupBy('e.id')
|
||||||
->getQuery();
|
->getQuery();
|
||||||
|
|
||||||
$data = $this->enableCache($query)
|
$query->useQueryCache(true);
|
||||||
->getArrayResult();
|
$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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb = $this->tagRepository->findAllTags($user->getId());
|
$data = $this->tagRepository->findAllTags($user->getId());
|
||||||
|
|
||||||
$data = $this->enableCache($qb->getQuery())
|
|
||||||
->getArrayResult();
|
|
||||||
|
|
||||||
return count($data);
|
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()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'wallabag_extension';
|
return 'wallabag_extension';
|
||||||
|
|
Loading…
Reference in a new issue