Skip to content

Commit

Permalink
reload existing tag names only first time and after a tag name collit…
Browse files Browse the repository at this point in the history
…ion to avoid unnecessary database queries
  • Loading branch information
bduran82 committed Jun 19, 2017
1 parent 4d9a10c commit d43736f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ def self.find_or_create_all_with_like_by_name(*list)

return [] if list.empty?

existing_tags = named_any(list)
list.map do |tag_name|
begin
tries ||= 3

existing_tags = named_any(list)
comparable_tag_name = comparable_name(tag_name)
existing_tag = existing_tags.find { |tag| comparable_name(tag.name) == comparable_tag_name }
existing_tag || create(name: tag_name)
rescue ActiveRecord::RecordNotUnique
if (tries -= 1).positive?
ActiveRecord::Base.connection.execute 'ROLLBACK'
existing_tags = named_any(list)
retry
end

Expand Down

0 comments on commit d43736f

Please sign in to comment.