]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
Merge remote-tracking branch 'origin/master' into 2.2
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / RuleBasedTagger.php
index 14ef4a6411928b439e33b399bee866c40d2c2859..b490e2090b4a95d5f263b1d1c5f9d17be8cdc9d3 100644 (file)
@@ -25,7 +25,7 @@ class RuleBasedTagger
     /**
      * Add tags from rules defined by the user.
      *
-     * @param Entry $entry Entry to tag.
+     * @param Entry $entry Entry to tag
      */
     public function tag(Entry $entry)
     {
@@ -49,12 +49,13 @@ class RuleBasedTagger
      *
      * @param User $user
      *
-     * @return array<Entry> A list of modified entries.
+     * @return array<Entry> A list of modified entries
      */
     public function tagAllForUser(User $user)
     {
         $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);
                 }
@@ -75,7 +81,7 @@ class RuleBasedTagger
     /**
      * Fetch a tag.
      *
-     * @param string $label The tag's label.
+     * @param string $label The tag's label
      *
      * @return Tag
      */