]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
Avoid tag duplication when tagging all articles
[github/wallabag/wallabag.git] / 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);
                 }