Skip to content

Do not add the same tag multiple times #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2018

Conversation

Toflar
Copy link
Contributor

@Toflar Toflar commented Jul 30, 2018

No description provided.

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think when we wrote this, we assumed that the application would not add tags multiple times, but now that i think about it, thats not a good assumption as it could make taging a lot more complicated in flexible and modular systems.

thanks for the pull request.

$headerFormatter = new CommaSeparatedTagHeaderFormatter('FOS-Tags');

$tagHandler = new ResponseTagger(['header_formatter' => $headerFormatter, 'strict' => true]);
$tagHandler->addTags(['post-1', 'post-2', 'post-1']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the sake of completeness, i'd like to have another line here that does $tagHandler->addTags(['post-2', 'post-3']);. with the current test, array_merge($this->tags, array_unique($filtered)) would pass but its not correct.

@@ -123,7 +123,7 @@ public function addTags(array $tags)
throw new InvalidTagException('Empty tags are not allowed');
}

$this->tags = array_merge($this->tags, $filtered);
$this->tags = array_unique(array_merge($this->tags, $filtered));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am pondering whether we should do the unique only at the end when building the tags header. not sure whats better performance - doing unique only at the end in getTagsHeaderValue would add less overhead for people who's system is not adding duplicate tags. on the other hand, a system with massive duplicates would profit from a rolling de-duplication. also depends on whether addTags is called a lot or only a few times... wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked myself the same question but in the end I guess it's such a minor thing, nobody will ever notice 😄 I put it into the addTags() because there's already some filtering going on there. I just figured it would be better to add it there so it's all in one place. But again, at the end of the day it doesn't really matter I think 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed

@dbu
Copy link
Contributor

dbu commented Jul 30, 2018

can you please add the changelog entry? otherwise this looks good to me

@dbu
Copy link
Contributor

dbu commented Jul 30, 2018

please rebase on master before adding the changelog to avoid a merge conflict ;-)

@Toflar
Copy link
Contributor Author

Toflar commented Jul 30, 2018

Done.

@dbu dbu merged commit 4959b5d into FriendsOfSymfony:master Jul 30, 2018
@dbu
Copy link
Contributor

dbu commented Jul 30, 2018

i tagged the changes as 2.4.0

thanks a lot for the contributions!

@Toflar Toflar deleted the unique-tags branch July 30, 2018 11:48
@Toflar
Copy link
Contributor Author

Toflar commented Jul 30, 2018

Yeyy, thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants