]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Avoid tag duplication when tagging all articles
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 9 Oct 2016 16:32:17 +0000 (18:32 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 9 Oct 2016 16:55:21 +0000 (18:55 +0200)
Mostly when the tag doesn’t yet exist.
It was created each time it matche the rule… glups.

src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php

index 239d09ae7bd8ff7f13dd8aeb74d12884621476db..b490e2090b4a95d5f263b1d1c5f9d17be8cdc9d3 100644 (file)
@@ -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);
                 }