Skip to content

Comments

Optimize Tag List Page Performance#6398

Merged
WithoutPants merged 1 commit intostashapp:developfrom
cj12312021:optimize-fragment-used-on-tags-list-page
Dec 11, 2025
Merged

Optimize Tag List Page Performance#6398
WithoutPants merged 1 commit intostashapp:developfrom
cj12312021:optimize-fragment-used-on-tags-list-page

Conversation

@cj12312021
Copy link
Collaborator

Summary:

  • Reduce tag list page query time by ~11x (tested on my production database) by eliminating expensive recursive count queries that weren't displayed on the list page
  • Created optimized TagListData GraphQL fragment that excludes *_count_all fields
  • Tag list page now loads in ~18ms instead of ~205ms (for 20 tags)

Problem:
The tag list page was slow to load because for every tag displayed, the TagData fragment requested 14 count fields:

  • 7 direct counts (scene_count, image_count, etc.)
  • 7 recursive counts (scene_count_all, image_count_all, etc. with depth: -1)

The recursive *_count_all fields use expensive recursive common table expressions to traverse the tag hierarchy and count all descendants. With 9M+ rows in my scenes_tags, this was extremely slow.
The *_count_all fields were fetched but never displayed on the list page - they're only used on the tag detail page.

Solution:
Created a new TagListData fragment and FindTagsForList query that only fetches the direct counts needed for the list page display.

@cj12312021 cj12312021 added improvement Something needed tweaking. backend Pull requests that update Go code labels Dec 11, 2025
@cj12312021 cj12312021 marked this pull request as ready for review December 11, 2025 02:38
@cj12312021
Copy link
Collaborator Author

Did a bit more testing with this change on my DB. The result is so much better. I've moved the PR out of Draft.

@WithoutPants WithoutPants removed the backend Pull requests that update Go code label Dec 11, 2025
@WithoutPants WithoutPants added this to the Version 0.30.0 milestone Dec 11, 2025
@WithoutPants WithoutPants merged commit f1e54bf into stashapp:develop Dec 11, 2025
2 checks passed
@sezzim sezzim mentioned this pull request Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Something needed tweaking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants