From b4fcd60e7f217bf0b23fa99c83698e7407bee54b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:32:17 +0200 Subject: [PATCH] Avoid tag duplication when tagging all articles MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 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(-) 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); } -- 2.41.0