Skip to content
Snippets Groups Projects
Unverified Commit cd063eec authored by Alexis Reigel's avatar Alexis Reigel
Browse files

optimize sql query to get tags related to runners

The query generated by ActsAsTaggableOn `@taggable_type.all_tags` is
very inefficient (joins too much, grouping, inner select, ...).
parent 1edeecb0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -11,21 +11,31 @@ module Autocomplete
end
 
def execute
@tags = @taggable_type.all_tags
@tags = ::ActsAsTaggableOn::Tag.all
 
filter_by_taggable_type!
search!
limit!
 
@tags
end
 
def filter_by_taggable_type!
# rubocop: disable CodeReuse/ActiveRecord
@tags = @tags
.joins(:taggings)
.where(taggings: { taggable_type: @taggable_type.name })
.distinct
# rubocop: enable CodeReuse/ActiveRecord
end
def search!
search = @params[:search]
 
return unless search
 
if search.empty?
@tags = @taggable_type.none
@tags = ::ActsAsTaggableOn::Tag.none
return
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment