You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running on Rails 4.2.8 and gem version 5.0.0 we experience a poor performance when updating the tags of a model with big number of tags.
In our project we need to handle models with sometimes big number of tags (up to around 300). We have experienced performance issues in our database when updating tags in those models that even led to request timeouts. The source seems to be the huge amount of database queries like the following:
SELECT `tags`.* FROM `tags` WHERE (name = BINARY 'editor' OR name = BINARY 'funding' OR name = BINARY 'transfers' OR name = BINARY 'role' OR name = BINARY 'editorial' OR ...
It looks like in ActsAsTaggableOn::Tag find_or_create_all_with_like_by_name all the tags attached to the model are repeatedly reloaded for every tag to avoid collisions in the database. Shouldn't the tags be loaded once in the beginning of the method and then only refreshed again in case there is a collision?
def self.find_or_create_all_with_like_by_name(*list)
list = Array(list).flatten
return [] if list.empty?
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'
retry
end
raise DuplicateTagError.new("'#{tag_name}' has already been taken")
end
end
end
The text was updated successfully, but these errors were encountered:
Running on Rails 4.2.8 and gem version 5.0.0 we experience a poor performance when updating the tags of a model with big number of tags.
In our project we need to handle models with sometimes big number of tags (up to around 300). We have experienced performance issues in our database when updating tags in those models that even led to request timeouts. The source seems to be the huge amount of database queries like the following:
SELECT `tags`.* FROM `tags` WHERE (name = BINARY 'editor' OR name = BINARY 'funding' OR name = BINARY 'transfers' OR name = BINARY 'role' OR name = BINARY 'editorial' OR ...
It looks like in
ActsAsTaggableOn::Tag find_or_create_all_with_like_by_name
all the tags attached to the model are repeatedly reloaded for every tag to avoid collisions in the database. Shouldn't the tags be loaded once in the beginning of the method and then only refreshed again in case there is a collision?The text was updated successfully, but these errors were encountered: