/**
* 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)
{
*
* @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 = array();
+ $entries = [];
+ $tagsCache = [];
foreach ($rules as $rule) {
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
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);
}
/**
* Fetch a tag.
*
- * @param string $label The tag's label.
+ * @param string $label The tag's label
*
* @return Tag
*/