diff options
-rwxr-xr-x | app/Resources/static/themes/material/css/main.css | 4 | ||||
-rw-r--r-- | app/config/config.yml | 1 | ||||
-rw-r--r-- | app/config/config_dev.yml | 8 | ||||
-rw-r--r-- | app/config/services.yml | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php | 1 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 24 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/config/services.yml | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig | 8 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 46 |
10 files changed, 95 insertions, 5 deletions
diff --git a/app/Resources/static/themes/material/css/main.css b/app/Resources/static/themes/material/css/main.css index 68f3f2ee..f4230734 100755 --- a/app/Resources/static/themes/material/css/main.css +++ b/app/Resources/static/themes/material/css/main.css | |||
@@ -308,6 +308,10 @@ nav input { | |||
308 | margin: 0 1rem; | 308 | margin: 0 1rem; |
309 | } | 309 | } |
310 | 310 | ||
311 | span.numberItems { | ||
312 | float: right; | ||
313 | } | ||
314 | |||
311 | /* ========================================================================== | 315 | /* ========================================================================== |
312 | * 3 = Filters slider | 316 | * 3 = Filters slider |
313 | * ========================================================================== */ | 317 | * ========================================================================== */ |
diff --git a/app/config/config.yml b/app/config/config.yml index 30fd6063..31bd8a8c 100644 --- a/app/config/config.yml +++ b/app/config/config.yml | |||
@@ -49,6 +49,7 @@ wallabag_core: | |||
49 | language: en | 49 | language: en |
50 | rss_limit: 50 | 50 | rss_limit: 50 |
51 | reading_speed: 1 | 51 | reading_speed: 1 |
52 | cache_lifetime: 10 | ||
52 | 53 | ||
53 | wallabag_user: | 54 | wallabag_user: |
54 | registration_enabled: "%fosuser_registration%" | 55 | registration_enabled: "%fosuser_registration%" |
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: | |||
40 | transport: smtp | 40 | transport: smtp |
41 | host: 'localhost' | 41 | host: 'localhost' |
42 | port: 1025 | 42 | port: 1025 |
43 | |||
44 | # If you want to use cache for queries used in WallabagExtension | ||
45 | # Uncomment the following lines | ||
46 | #doctrine: | ||
47 | # orm: | ||
48 | # metadata_cache_driver: apcu | ||
49 | # result_cache_driver: apcu | ||
50 | # query_cache_driver: apcu | ||
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: | |||
16 | wallabag.twig_extension: | 16 | wallabag.twig_extension: |
17 | class: Wallabag\CoreBundle\Twig\WallabagExtension | 17 | class: Wallabag\CoreBundle\Twig\WallabagExtension |
18 | public: false | 18 | public: false |
19 | arguments: | ||
20 | - "@wallabag_core.entry_repository" | ||
21 | - "@security.token_storage" | ||
19 | tags: | 22 | tags: |
20 | - { name: twig.extension } | 23 | - { name: twig.extension } |
21 | 24 | ||
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 | |||
36 | ->end() | 36 | ->end() |
37 | ->scalarNode('paypal_url') | 37 | ->scalarNode('paypal_url') |
38 | ->end() | 38 | ->end() |
39 | ->integerNode('cache_lifetime') | ||
40 | ->defaultValue(10) | ||
41 | ->end() | ||
39 | ->end() | 42 | ->end() |
40 | ; | 43 | ; |
41 | 44 | ||
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 | |||
22 | $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']); | 22 | $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']); |
23 | $container->setParameter('wallabag_core.version', $config['version']); | 23 | $container->setParameter('wallabag_core.version', $config['version']); |
24 | $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); | 24 | $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); |
25 | $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); | ||
25 | 26 | ||
26 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | 27 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27 | $loader->load('services.yml'); | 28 | $loader->load('services.yml'); |
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index e5c21679..24d1a57a 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -3,12 +3,15 @@ | |||
3 | namespace Wallabag\CoreBundle\Repository; | 3 | namespace Wallabag\CoreBundle\Repository; |
4 | 4 | ||
5 | use Doctrine\ORM\EntityRepository; | 5 | use Doctrine\ORM\EntityRepository; |
6 | use Doctrine\ORM\Query; | ||
6 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 7 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
7 | use Pagerfanta\Pagerfanta; | 8 | use Pagerfanta\Pagerfanta; |
8 | use Wallabag\CoreBundle\Entity\Tag; | 9 | use Wallabag\CoreBundle\Entity\Tag; |
9 | 10 | ||
10 | class EntryRepository extends EntityRepository | 11 | class EntryRepository extends EntityRepository |
11 | { | 12 | { |
13 | private $lifeTime; | ||
14 | |||
12 | /** | 15 | /** |
13 | * Return a query builder to used by other getBuilderFor* method. | 16 | * Return a query builder to used by other getBuilderFor* method. |
14 | * | 17 | * |
@@ -308,4 +311,25 @@ class EntryRepository extends EntityRepository | |||
308 | 311 | ||
309 | return $qb->getQuery()->getSingleScalarResult(); | 312 | return $qb->getQuery()->getSingleScalarResult(); |
310 | } | 313 | } |
314 | |||
315 | public function setLifeTime($lifeTime) | ||
316 | { | ||
317 | $this->lifeTime = $lifeTime; | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Enable cache for a query. | ||
322 | * | ||
323 | * @param Query $query | ||
324 | * | ||
325 | * @return Query | ||
326 | */ | ||
327 | public function enableCache(Query $query) | ||
328 | { | ||
329 | $query->useQueryCache(true); | ||
330 | $query->useResultCache(true); | ||
331 | $query->setResultCacheLifetime($this->lifeTime); | ||
332 | |||
333 | return $query; | ||
334 | } | ||
311 | } | 335 | } |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index e95ef452..1c1457e7 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -81,6 +81,8 @@ services: | |||
81 | factory: [ "@doctrine.orm.default_entity_manager", getRepository ] | 81 | factory: [ "@doctrine.orm.default_entity_manager", getRepository ] |
82 | arguments: | 82 | arguments: |
83 | - WallabagCoreBundle:Entry | 83 | - WallabagCoreBundle:Entry |
84 | calls: | ||
85 | - [ setLifeTime, [ "%wallabag_core.cache_lifetime%" ] ] | ||
84 | 86 | ||
85 | wallabag_core.tag_repository: | 87 | wallabag_core.tag_repository: |
86 | class: Wallabag\CoreBundle\Repository\TagRepository | 88 | class: Wallabag\CoreBundle\Repository\TagRepository |
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 @@ | |||
35 | {% set currentRoute = app.request.attributes.get('_route') %} | 35 | {% set currentRoute = app.request.attributes.get('_route') %} |
36 | 36 | ||
37 | <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}"> | 37 | <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}"> |
38 | <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }}</a> | 38 | <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }} <span class="numberItems grey-text">{{ unreadEntries }}</span></a> |
39 | </li> | 39 | </li> |
40 | <li class="bold {% if currentRoute == 'starred' %}active{% endif %}"> | 40 | <li class="bold {% if currentRoute == 'starred' %}active{% endif %}"> |
41 | <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }}</a> | 41 | <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }} <span class="numberItems grey-text">{{ starredEntries }}</span></a> |
42 | </li> | 42 | </li> |
43 | <li class="bold {% if currentRoute == 'archive' %}active{% endif %}"> | 43 | <li class="bold {% if currentRoute == 'archive' %}active{% endif %}"> |
44 | <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }}</a> | 44 | <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }} <span class="numberItems grey-text">{{ archivedEntries }}</span></a> |
45 | </li> | 45 | </li> |
46 | <li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}"> | 46 | <li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}"> |
47 | <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }}</a> | 47 | <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }} <span class="numberItems grey-text">{{ allEntries }}</span></a> |
48 | </li> | 48 | </li> |
49 | <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}"> | 49 | <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}"> |
50 | <a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a> | 50 | <a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a> |
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 1a308070..5c475d61 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php | |||
@@ -2,8 +2,20 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Twig; | 3 | namespace Wallabag\CoreBundle\Twig; |
4 | 4 | ||
5 | class WallabagExtension extends \Twig_Extension | 5 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
6 | use Wallabag\CoreBundle\Repository\EntryRepository; | ||
7 | |||
8 | class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface | ||
6 | { | 9 | { |
10 | private $tokenStorage; | ||
11 | private $repository; | ||
12 | |||
13 | public function __construct(EntryRepository $repository = null, TokenStorageInterface $tokenStorage = null) | ||
14 | { | ||
15 | $this->repository = $repository; | ||
16 | $this->tokenStorage = $tokenStorage; | ||
17 | } | ||
18 | |||
7 | public function getFilters() | 19 | public function getFilters() |
8 | { | 20 | { |
9 | return [ | 21 | return [ |
@@ -16,6 +28,38 @@ class WallabagExtension extends \Twig_Extension | |||
16 | return preg_replace('/^www\./i', '', $url); | 28 | return preg_replace('/^www\./i', '', $url); |
17 | } | 29 | } |
18 | 30 | ||
31 | public function getGlobals() | ||
32 | { | ||
33 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | ||
34 | |||
35 | if (null === $user || !is_object($user)) { | ||
36 | return array(); | ||
37 | } | ||
38 | |||
39 | $unreadEntries = $this->repository->enableCache( | ||
40 | $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery() | ||
41 | ); | ||
42 | |||
43 | $starredEntries = $this->repository->enableCache( | ||
44 | $this->repository->getBuilderForStarredByUser($user->getId())->getQuery() | ||
45 | ); | ||
46 | |||
47 | $archivedEntries = $this->repository->enableCache( | ||
48 | $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery() | ||
49 | ); | ||
50 | |||
51 | $allEntries = $this->repository->enableCache( | ||
52 | $this->repository->getBuilderForAllByUser($user->getId())->getQuery() | ||
53 | ); | ||
54 | |||
55 | return array( | ||
56 | 'unreadEntries' => count($unreadEntries->getResult()), | ||
57 | 'starredEntries' => count($starredEntries->getResult()), | ||
58 | 'archivedEntries' => count($archivedEntries->getResult()), | ||
59 | 'allEntries' => count($allEntries->getResult()), | ||
60 | ); | ||
61 | } | ||
62 | |||
19 | public function getName() | 63 | public function getName() |
20 | { | 64 | { |
21 | return 'wallabag_extension'; | 65 | return 'wallabag_extension'; |