fix(tags): fandom views aggregate images via their characters #130
Reference in New Issue
Block a user
Delete Branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Browse fandom cards and the gallery fandom filter showed only images tagged with the fandom directly — images carrying one of the fandom's characters (the common case) were invisible to it.
Root cause:
character.fandom_idmodels fandom ownership, but every image↔tag query routed purely through directimage_tagrows and never used the FK.Fix (derive at query time, not propagate): one shared membership predicate in
tag_query.py—image_in_tag_scope/image_in_any_tag_scope(an image belongs to a tag if tagged directly OR, when the tag is a fandom, carrying a character whosefandom_idis that tag; the character leg is empty for non-fandom tags, so it applies uniformly). Routed through:_apply_scope— include, OR-groups, and symmetric excludeimage_count— correlatedCOUNT(DISTINCT)scalar subqueryUNIONof direct + via-character, thenROW_NUMBER <= 3count_tag_associations— Tier-B delete prompt now reports a fandom's true blast radiuscharacter.fandom_idstays the single source of truth (no materialized rows to reconcile on reassign/merge/remove); tagging flow unchanged. Tests added in test_gallery_service / test_tag_directory_service / test_cleanup_service. CI green on dev (run 1509).🤖 Generated with Claude Code