From: Jeremy Benoist Date: Sun, 9 Oct 2016 16:32:17 +0000 (+0200) Subject: Avoid tag duplication when tagging all articles X-Git-Tag: 2.1.2~28^2~2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=b4fcd60e7f217bf0b23fa99c83698e7407bee54b;hp=4d318f37555772e43906d917a1c8594cec040acf;p=github%2Fwallabag%2Fwallabag.git Avoid tag duplication when tagging all articles Mostly when the tag doesn’t yet exist. It was created each time it matche the rule… glups. --- 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); }