From 8315130a75c8f411f76134b6205a017409583d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 21 Apr 2016 22:30:50 +0200 Subject: Display entries number for each category --- app/Resources/static/themes/material/css/main.css | 4 +++ app/config/services.yml | 3 ++ .../views/themes/material/layout.html.twig | 8 +++--- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 33 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/Resources/static/themes/material/css/main.css b/app/Resources/static/themes/material/css/main.css index cade37f6..99892401 100755 --- a/app/Resources/static/themes/material/css/main.css +++ b/app/Resources/static/themes/material/css/main.css @@ -303,6 +303,10 @@ nav input { margin: 0 1rem; } +span.numberItems { + float: right; +} + /* ========================================================================== * 3 = Filters slider * ========================================================================== */ diff --git a/app/config/services.yml b/app/config/services.yml index 480408d9..95b8f26f 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -16,6 +16,9 @@ services: wallabag.twig_extension: class: Wallabag\CoreBundle\Twig\WallabagExtension public: false + arguments: + - "@wallabag_core.entry_repository" + - "@security.token_storage" tags: - { name: twig.extension } diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index 50134357..f64c3da2 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -35,16 +35,16 @@ {% set currentRoute = app.request.attributes.get('_route') %}
  • - {{ 'menu.left.unread'|trans }} + {{ 'menu.left.unread'|trans }} {{ unreadEntries }}
  • - {{ 'menu.left.starred'|trans }} + {{ 'menu.left.starred'|trans }} {{ starredEntries }}
  • - {{ 'menu.left.archive'|trans }} + {{ 'menu.left.archive'|trans }} {{ archivedEntries }}
  • - {{ 'menu.left.all_articles'|trans }} + {{ 'menu.left.all_articles'|trans }} {{ allEntries }}
  • {{ 'menu.left.tags'|trans }} diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 1a308070..c116248f 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -2,8 +2,20 @@ namespace Wallabag\CoreBundle\Twig; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Wallabag\CoreBundle\Repository\EntryRepository; + class WallabagExtension extends \Twig_Extension { + private $tokenStorage; + private $repository; + + public function __construct(EntryRepository $repository = null, TokenStorageInterface $tokenStorage = null) + { + $this->repository = $repository; + $this->tokenStorage = $tokenStorage; + } + public function getFilters() { return [ @@ -16,6 +28,27 @@ class WallabagExtension extends \Twig_Extension return preg_replace('/^www\./i', '', $url); } + public function getGlobals() + { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !is_object($user)) { + 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(); + + return array( + 'unreadEntries' => count($unreadEntries), + 'starredEntries' => count($starredEntries), + 'archivedEntries' => count($archivedEntries), + 'allEntries' => count($allEntries), + ); + } + public function getName() { return 'wallabag_extension'; -- cgit v1.2.3 From f997ae6afb72e6a2f3d8ff8bd30a354e35696410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 21 Apr 2016 22:35:42 +0200 Subject: Implement Twig_Extension_GlobalsInterface to remove deprecation --- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index c116248f..6e46c701 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -5,7 +5,7 @@ namespace Wallabag\CoreBundle\Twig; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Repository\EntryRepository; -class WallabagExtension extends \Twig_Extension +class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface { private $tokenStorage; private $repository; -- cgit v1.2.3 From 0b0233b1ec8208be47c76856a4e317673927b21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 1 Sep 2016 20:20:12 +0200 Subject: Enable cache for queries --- .../CoreBundle/Repository/EntryRepository.php | 17 ++++++++++++++ src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 27 +++++++++++++++------- 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 @@ 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; + } } 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 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()), ); } -- cgit v1.2.3 From b3f4a11a81b520b8dcc2bcebeeafea2cc0338a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Sep 2016 14:02:50 +0200 Subject: Store cache lifetime in config --- app/config/config.yml | 1 + app/config/config_dev.yml | 8 ++++++++ src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | 3 +++ .../CoreBundle/DependencyInjection/WallabagCoreExtension.php | 1 + src/Wallabag/CoreBundle/Repository/EntryRepository.php | 11 +++++++++-- src/Wallabag/CoreBundle/Resources/config/services.yml | 2 ++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index 80754393..eb53fc5d 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -49,6 +49,7 @@ wallabag_core: language: en rss_limit: 50 reading_speed: 1 + cache_lifetime: 10 wallabag_import: allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain'] diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index 77840682..3b67d8f6 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -40,3 +40,11 @@ swiftmailer: transport: smtp host: 'localhost' port: 1025 + +# If you want to use cache for queries used in WallabagExtension +# Uncomment the following lines +#doctrine: +# orm: +# metadata_cache_driver: apcu +# result_cache_driver: apcu +# query_cache_driver: apcu diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index d1bb9820..d8141eea 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -36,6 +36,9 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('paypal_url') ->end() + ->integerNode('cache_lifetime') + ->defaultValue(10) + ->end() ->end() ; diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index 7d08b73b..0cbde908 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -22,6 +22,7 @@ class WallabagCoreExtension extends Extension $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']); $container->setParameter('wallabag_core.version', $config['version']); $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); + $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 86bce545..4b205f6e 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -10,6 +10,8 @@ use Wallabag\CoreBundle\Entity\Tag; class EntryRepository extends EntityRepository { + private $lifeTime; + /** * Return a query builder to used by other getBuilderFor* method. * @@ -281,8 +283,13 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getSingleScalarResult(); } + public function setLifeTime($lifeTime) + { + $this->lifeTime = $lifeTime; + } + /** - * Enable cache for a query + * Enable cache for a query. * * @param Query $query * @@ -292,7 +299,7 @@ class EntryRepository extends EntityRepository { $query->useQueryCache(true); $query->useResultCache(true); - $query->setResultCacheLifetime(5); + $query->setResultCacheLifetime($this->lifeTime); return $query; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index f8835198..b70d9b8c 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -81,6 +81,8 @@ services: factory: [ "@doctrine.orm.default_entity_manager", getRepository ] arguments: - WallabagCoreBundle:Entry + calls: + - [ setLifeTime, [ "%wallabag_core.cache_lifetime%" ] ] wallabag_core.tag_repository: class: Wallabag\CoreBundle\Repository\TagRepository -- cgit v1.2.3