Skip to content

Batch user role loading - #1240

Open
slick-daddy wants to merge 2 commits into
stashapp:masterfrom
slick-daddy:opt-15
Open

Batch user role loading#1240
slick-daddy wants to merge 2 commits into
stashapp:masterfrom
slick-daddy:opt-15

Conversation

@slick-daddy

Copy link
Copy Markdown
Contributor

The admin users list requests roles for every user. Previously, User.Roles executed one database query per user, creating an N+1 query pattern.

This change adds a UserRolesByID dataloader that:

  • Uses the existing StringsLoader because roles are stored as strings and converted to GraphQL enums by the resolver.
  • Batches up to 1,000 user IDs per fetch, matching existing dataloader limits.
  • Waits 1 millisecond to collect role requests from multiple users into one query.
  • Delegates database access to User.LoadRoles, keeping SQL and service logic outside the resolver.
  • Maps results back to the original user-ID order, including users with no roles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant