Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
341c874
First batch of work
ReverM Dec 15, 2025
905d4f7
Added restriction to the tag pages
ReverM Dec 15, 2025
7ad262f
Merge branch 'otwcode:master' into AO3-6067
ReverM Dec 15, 2025
05bf0e1
Reverted autostyle
ReverM Dec 15, 2025
8502d6c
Merge branch 'otwcode:master' into AO3-6067
ReverM Dec 17, 2025
d9c3cbe
Test + Fix
ReverM Dec 18, 2025
a5f3f67
Merge branch 'AO3-6067' of https://github.com/ReverM/otwarchive into …
ReverM Dec 18, 2025
d5c7307
Changed some names for readability
ReverM Dec 18, 2025
e27e433
Did not forget linter, forgot rubocop
ReverM Dec 18, 2025
d109571
Add test for no double counts
ReverM Dec 19, 2025
556d1e7
Made sure that non-canonical aren't shown as well
ReverM Dec 19, 2025
e876c2b
Update app/models/search/search_counts.rb
ReverM Jan 1, 2026
fac8449
Changed behaviour when looking at collection specific tag
ReverM Jan 8, 2026
9e8fa6f
Fixed lint issue
ReverM Jan 8, 2026
dd384ef
disabled caching
ReverM Jan 12, 2026
ce9edfc
Adressed comment and tried suggestion to make test work
ReverM Jan 14, 2026
8db30ad
Moved suggestion
ReverM Jan 14, 2026
e0d1c2a
Maybe here will work?
ReverM Jan 14, 2026
4ed7df5
Maybe this will do?
ReverM Jan 15, 2026
ee889fb
Trying something before resorting to writing a spec test
ReverM Jan 15, 2026
c225c80
For testing what the output is on GitHub's autotest
ReverM Jan 15, 2026
cd6206f
Attempt at a fix
ReverM Jan 17, 2026
27c6d96
Changed search_count to see if it is more robust against test
ReverM Jan 17, 2026
c37aac8
Applied suggestiong to not have ifthen
ReverM Jan 20, 2026
9a783e2
Requested changes to tests
ReverM Jan 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/fandoms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ 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
@collections = @tag.collections
# if from a collection, only show items from that collection
if @collection.present?
@works &= @collection.works
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not include works in the subcollections, but the counts on the collection page do include them, so this is a mismatch - I can click on "new fandom (1)" and get to a page with no works. For canonical tags the works from the subcollections are included, so we should do the same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, is there a quick way of having a list of collection from a parent collection? (since I assume child of child are also included)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, child collections can't have children -- subcollections only go one level deep.

@bookmarks &= @collection.bookmarks
@collections &= @collection.children
end
@works = @works.paginate(page: params[:page])
@bookmarks = @tag.bookmarks.visible.paginate(page: params[:page])
@collections = @tag.collections.paginate(page: params[:page])
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions app/models/search/search_counts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -114,6 +114,18 @@ 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|
list |= work.fandom_ids if work.fandom_ids.present?
work.tag_groups["Fandom"].each do |fandom|
list.push(fandom.id) if Fandom.find_by(id: fandom.id).unwrangled?
end
end
list.tally
end

######################################################################
# CACHE OPTIONS
######################################################################
Expand Down
43 changes: 43 additions & 0 deletions features/collections/collection_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,49 @@ Feature: Basic collection navigation
Then I should not see "High School Musical"
And I should see "Steven's Universe"

Scenario: Uncategorized Fandoms should appear in Collection's Fandoms
Given I have the collection "Categoric" with name "categoric"
And the tag "Unrelated Fandom" does not exist
And I have a canonical "Video Games" fandom tag named "Undertale"
When I am logged in as "Frisk"
And I post the work "Categoric Sans" with fandom "Undertale" in the collection "Categoric"
And I post the work "Categoric Papyrus" with fandom "Undertale"
And I post the work "Uncategoric Sans" with fandom "Unrelated Fandom" in the collection "Categoric"
And I post the work "Uncategoric Papyrus" with fandom "Unrelated Fandom"
And I go to "Categoric" collection's page
Then I should see "Fandoms (2)"
When I follow "Fandoms (2)"
Then I should see "Unrelated Fandom"
And I should see "Undertale"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also check the counts here

When I select "Uncategorized Fandoms" from "media_id"
And I press "Show"
Then I should see "Unrelated Fandom"
And I should not see "Undertale"

# From collection we only see the works in the collection
When I follow "Unrelated Fandom"
Then I should see "Sans"
And I should not see "Papyrus"

# Else we see all
When I follow "Uncategorized Fandoms" within "#header"
And I follow "Unrelated Fandom"
Then I should see "Sans"
And I should see "Papyrus"

Scenario: Non-Canonical Fandoms are not double counted
Given I have the collection "Canons" with name "canon"
And I have a canonical "TV Shows" fandom tag named "TV"
And a synonym "Television" of the tag "TV"
When I am logged in as "Screen"
And I post the work "Full name" with fandom "Television" in the collection "Canons"
And I post the work "Small name" with fandom "TV" in the collection "Canons"
And I go to "Canons" collection's page
Then I should see "Fandoms (1)"
And I should see "Television"
When I follow "Fandoms (1)"
Then I should not see "Television"

Scenario: Browse tags within a collection (or not)
Given I have a collection "Randomness"
And a canonical fandom "Naruto"
Expand Down
Loading