diff --git a/app/controllers/fandoms_controller.rb b/app/controllers/fandoms_controller.rb index 8a105ce0993..62828f19a27 100644 --- a/app/controllers/fandoms_controller.rb +++ b/app/controllers/fandoms_controller.rb @@ -3,7 +3,7 @@ class FandomsController < ApplicationController def index if @collection - @media = Media.canonical.by_name - [Media.find_by(name: ArchiveConfig.MEDIA_NO_TAG_NAME)] - [Media.find_by(name: ArchiveConfig.MEDIA_UNCATEGORIZED_NAME)] + @media = Media.canonical.by_name.where.not(name: [ArchiveConfig.MEDIA_UNCATEGORIZED_NAME, ArchiveConfig.MEDIA_NO_TAG_NAME]) + [Media.uncategorized] @page_subtitle = t(".collection_page_title", collection_title: @collection.title) @medium = Media.find_by_name(params[:media_id]) if params[:media_id] @counts = SearchCounts.fandom_ids_for_collection(@collection) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 28924281678..d80abeeda9c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -70,14 +70,23 @@ def show # if tag is NOT wrangled, prepare to show works, collections, and bookmarks that are using it if !@tag.canonical && !@tag.merger @works = if logged_in? # current_user.is_a?User - @tag.works.visible_to_registered_user.paginate(page: params[:page]) + @tag.works.visible_to_registered_user elsif logged_in_as_admin? - @tag.works.visible_to_admin.paginate(page: params[:page]) + @tag.works.visible_to_admin else - @tag.works.visible_to_all.paginate(page: params[:page]) + @tag.works.visible_to_all end - @bookmarks = @tag.bookmarks.visible.paginate(page: params[:page]) - @collections = @tag.collections.paginate(page: params[:page]) + @bookmarks = @tag.bookmarks.visible + @collections = @tag.collections + # if from a collection, only show works from that collection + if @collection.present? + @works &= @collection.works + @bookmarks = [] + @collections = [] + end + @works = @works.paginate(page: params[:page]) + @bookmarks = @bookmarks.paginate(page: params[:page]) + @collections = @collections.paginate(page: params[:page]) end # cache the children, since it's a possibly massive query @tag_children = Rails.cache.fetch "views/tags/#{@tag.cache_key}/children" do diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index b42c7470c4e..be16e53d76c 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -734,6 +734,8 @@ def load_owner else redirect_to(tag_works_path(@tag.merger)) && return end + elsif @collection.present? + redirect_to(collection_tag_path(@collection, @tag)) && return else redirect_to(tag_path(@tag)) && return end diff --git a/app/models/search/search_counts.rb b/app/models/search/search_counts.rb index 5d4fada249d..44f8f568c39 100644 --- a/app/models/search/search_counts.rb +++ b/app/models/search/search_counts.rb @@ -32,14 +32,14 @@ def bookmarkable_count_for_collection(collection) def fandom_count_for_collection(collection) Rails.cache.fetch(collection_cache_key(collection, :fandom_count), collection_cache_options) do - collection_works_query(collection).field_count(:fandom_ids) + get_fandom_hash(collection_works_query(collection)).count end end def fandom_ids_for_collection(collection) Rails.cache.fetch(collection_cache_key(collection, :fandom_ids), collection_cache_options) do - collection_works_query(collection).field_values(:fandom_ids) + get_fandom_hash(collection_works_query(collection)) end end @@ -114,6 +114,21 @@ def logged_in User.current_user ? :logged_in : :logged_out end + # Helper function to get both categorized and uncategorized fandoms from a WorkQuery object + def get_fandom_hash(query) + list = [] + query.search_results.each do |work| + work.fandoms.each do |fandom| + if fandom.unwrangled? || fandom.canonical? + list.push(fandom.id) + else + list.push(fandom.merger_id) + end + end + end + list.tally + end + ###################################################################### # CACHE OPTIONS ###################################################################### diff --git a/app/views/tags/show.html.erb b/app/views/tags/show.html.erb index 32a908401c3..d04b6d7ced6 100644 --- a/app/views/tags/show.html.erb +++ b/app/views/tags/show.html.erb @@ -115,7 +115,13 @@
<%= ts("This tag has not been marked common and can't be filtered on (yet).") %>
<% unless @works.blank? %>