forked from wallabag/wallabag
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.
This commit is contained in:
@ -55,6 +55,7 @@ class RuleBasedTagger
|
|||||||
{
|
{
|
||||||
$rules = $this->getRulesForUser($user);
|
$rules = $this->getRulesForUser($user);
|
||||||
$entries = [];
|
$entries = [];
|
||||||
|
$tagsCache = [];
|
||||||
|
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
|
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
|
||||||
@ -62,7 +63,12 @@ class RuleBasedTagger
|
|||||||
|
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
foreach ($rule->getTags() as $label) {
|
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);
|
$entry->addTag($tag);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user