From 4d318f37555772e43906d917a1c8594cec040acf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:31:30 +0200 Subject: Add more log to tag:all --- src/Wallabag/CoreBundle/Command/TagAllCommand.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Command/TagAllCommand.php b/src/Wallabag/CoreBundle/Command/TagAllCommand.php index db1a9ab7..3f9bb04d 100644 --- a/src/Wallabag/CoreBundle/Command/TagAllCommand.php +++ b/src/Wallabag/CoreBundle/Command/TagAllCommand.php @@ -34,10 +34,13 @@ class TagAllCommand extends ContainerAwareCommand } $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger'); - $output->write(sprintf('Tagging entries for user « %s »... ', $user->getUserName())); + $output->write(sprintf('Tagging entries for user « %s »... ', $user->getUserName())); $entries = $tagger->tagAllForUser($user); + $output->writeln('Done.'); + $output->write(sprintf('Persist entries ... ', $user->getUserName())); + $em = $this->getDoctrine()->getManager(); foreach ($entries as $entry) { $em->persist($entry); -- cgit v1.2.3 From b4fcd60e7f217bf0b23fa99c83698e7407bee54b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:32:17 +0200 Subject: Avoid tag duplication when tagging all articles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly when the tag doesn’t yet exist. It was created each time it matche the rule… glups. --- src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index 239d09ae..b490e209 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -55,6 +55,7 @@ class RuleBasedTagger { $rules = $this->getRulesForUser($user); $entries = []; + $tagsCache = []; foreach ($rules as $rule) { $qb = $this->entryRepository->getBuilderForAllByUser($user->getId()); @@ -62,7 +63,12 @@ class RuleBasedTagger foreach ($entries as $entry) { foreach ($rule->getTags() as $label) { - $tag = $this->getTag($label); + // avoid new tag duplicate by manually caching them + if (!isset($tagsCache[$label])) { + $tagsCache[$label] = $this->getTag($label); + } + + $tag = $tagsCache[$label]; $entry->addTag($tag); } -- cgit v1.2.3 From 28bb48905a2104adad65508f51737f987dc1ad4c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:41:19 +0200 Subject: Optimize the way tag list is rendered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of retrieve all informations about entries of a tag to just count them, we’ll count them before with a fastest query. Also change the layout of the tag list in material design --- .../ApiBundle/Controller/WallabagRestController.php | 2 +- src/Wallabag/CoreBundle/Controller/TagController.php | 19 +++++++++++++++++-- .../CoreBundle/Repository/EntryRepository.php | 20 ++++++++++++++++++++ src/Wallabag/CoreBundle/Repository/TagRepository.php | 10 +++++++--- .../Resources/views/themes/baggy/Tag/tags.html.twig | 2 +- .../views/themes/material/Tag/tags.html.twig | 17 ++++++++++++----- 6 files changed, 58 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index ed31c536..9997913d 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -387,7 +387,7 @@ class WallabagRestController extends FOSRestController $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTagsWithEntries($this->getUser()->getId()); + ->findAllTags($this->getUser()->getId()); $json = $this->get('serializer')->serialize($tags, 'json'); diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index c5746734..5acc6852 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -86,10 +86,25 @@ class TagController extends Controller { $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTagsWithEntries($this->getUser()->getId()); + ->findAllTags($this->getUser()->getId()); + + $flatTags = []; + + foreach ($tags as $key => $tag) { + $nbEntries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']); + + $flatTags[] = [ + 'id' => $tag['id'], + 'label' => $tag['label'], + 'slug' => $tag['slug'], + 'nbEntries' => $nbEntries, + ]; + } return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ - 'tags' => $tags, + 'tags' => $flatTags, ]); } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 75127b7d..cd2b47b9 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -309,4 +309,24 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getSingleScalarResult(); } + + /** + * Count all entries for a tag and a user. + * + * @param int $userId + * @param int $tagId + * + * @return int + */ + public function countAllEntriesByUserIdAndTagId($userId, $tagId) + { + $qb = $this->createQueryBuilder('e') + ->select('count(e.id)') + ->leftJoin('e.tags', 't') + ->where('e.user=:userId')->setParameter('userId', $userId) + ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId) + ; + + return $qb->getQuery()->getSingleScalarResult(); + } } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 9d127da7..e76878d4 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -33,19 +33,23 @@ class TagRepository extends EntityRepository } /** - * Find all tags with associated entries per user. + * Find all tags per user. * * @param int $userId * * @return array */ - public function findAllTagsWithEntries($userId) + public function findAllTags($userId) { return $this->createQueryBuilder('t') + ->select('t.slug', 't.label', 't.id') ->leftJoin('t.entries', 'e') ->where('e.user = :userId')->setParameter('userId', $userId) + ->groupBy('t.slug') + ->addGroupBy('t.label') + ->addGroupBy('t.id') ->getQuery() - ->getResult(); + ->getArrayResult(); } /** diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig index 50043907..1e2c6b42 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig @@ -9,7 +9,7 @@ diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig index 1690633a..96f4f990 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig @@ -6,12 +6,19 @@
{{ 'tag.list.number_on_the_page'|transchoice(tags|length) }}
+
- + +
+ +
+
{{ 'tag.list.see_untagged_entries'|trans }}
-- cgit v1.2.3