-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5120 – Dont create duplicate tags and clean up
#
(#2054)
Context While looking into a tags issue I noticed a few things: - when we made a request with duplicate tags: - we got an error, so the job was retried - the tag was added twice to the FactCheck - the tag is added once to the ProjectMedia - when we made a request with a tag with a # - we got an error, so the job was retried - there seem to have been two errors related to this: - ActiveRecord::RecordInvalid: Tag already exists - ActiveRecord::RecordInvalid: Text has already been taken - the tag with the # is added to the FactCheck - the tag is not added to the ProjectMedia What was happening There are a few things happening at the same time: - Creation of a ProjectMedia with tags - Creation of a FactCheck with tags - Tags are an Object from the Tag Class for ProjectMedia, but are a simple array for FactCheck For the ProjectMedia: - It would create the tag, then it would try to create the same tag again, and then it would fail and retry again, and so on - This happen because we have validations in place for the Tag class For FactCheck: - It would just create the tags twice - Because we have no validations for the tags array TLDR: There were some issues in the tags clean-up before we create them for ProjectMedia and FactCheck, and there was a mismatch between them. How it was fixed - I created a helper to clean up the tags before creating them - We need to make sure tags are: - stripped - unique - don't have a prepending `#` - We use this helper both in FactCheck.rb and Tag.rb References: 5120 PR: 2054
- Loading branch information
1 parent
a704dda
commit 7ac655d
Showing
11 changed files
with
166 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'active_support/concern' | ||
|
||
module TagHelpers | ||
extend ActiveSupport::Concern | ||
|
||
def clean_tags(tags) | ||
tags.map { |tag| tag.strip.gsub(/^#/, '') }.uniq | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters