diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 5df2f9c4d..00f53132a 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -6,13 +6,11 @@ class CollectionsController < ApplicationController before_action :get_collection, except: [:index, :new, :create] def index + @models = filtered_models @filters @collections = policy_scope(Collection) - unless @filters.empty? - @models = filtered_models @filters - @collections = @collections.tree_both(@filters[:collection] || nil, @models.filter_map { |model| model.collection_id }) - end + @collections = @collections.tree_both(@filters[:collection] || nil, @models.pluck(:collection_id).distinct) unless @filters.empty? - @tags, @unrelated_tag_count = generate_tag_list(@filters.empty? ? nil : @models, @filter_tags) + @tags, @unrelated_tag_count = generate_tag_list(@models, @filter_tags) @tags, @kv_tags = split_key_value_tags(@tags) # Ordering diff --git a/app/controllers/creators_controller.rb b/app/controllers/creators_controller.rb index 4aee5a70b..12a49d8e4 100644 --- a/app/controllers/creators_controller.rb +++ b/app/controllers/creators_controller.rb @@ -6,13 +6,11 @@ class CreatorsController < ApplicationController before_action :get_creator, except: [:index, :new, :create] def index + @models = filtered_models @filters @creators = policy_scope(Creator) - unless @filters.empty? - @models = filtered_models @filters - @creators = @creators.where(id: @models.map { |model| model.creator_id }) - end + @creators = @creators.where(id: @models.pluck(:creator_id).distinct) unless @filters.empty? - @tags, @unrelated_tag_count = generate_tag_list(@filters.empty? ? nil : @models, @filter_tags) + @tags, @unrelated_tag_count = generate_tag_list(@models, @filter_tags) @tags, @kv_tags = split_key_value_tags(@tags) # Ordering diff --git a/app/controllers/models_controller.rb b/app/controllers/models_controller.rb index 21edd96df..79df139f6 100644 --- a/app/controllers/models_controller.rb +++ b/app/controllers/models_controller.rb @@ -28,7 +28,7 @@ def index @models = @models.page(page).per(helpers.pagination_settings["per_page"]) end - @tags, @unrelated_tag_count = generate_tag_list(@filters.empty? ? nil : @models, @filter_tags) + @tags, @unrelated_tag_count = generate_tag_list(@models, @filter_tags) @tags, @kv_tags = split_key_value_tags(@tags) # Load extra data