Skip to content

feat(BA-4814): add DataLoader for batched role assignment queries by user#9552

Open
fregataa wants to merge 5 commits intomainfrom
BA-4814
Open

feat(BA-4814): add DataLoader for batched role assignment queries by user#9552
fregataa wants to merge 5 commits intomainfrom
BA-4814

Conversation

@fregataa
Copy link
Member

@fregataa fregataa commented Mar 1, 2026

Summary

  • Add load_role_assignments_by_user_ids DataLoader function for batched loading of role assignments grouped by user ID
  • Register role_assignments_by_user_loader in the central DataLoaders registry
  • Add my_roles field to UserV2GQL that uses the new DataLoader to prevent N+1 queries
  • Add AssignedUserConditions.by_user_ids() query condition for filtering by multiple user IDs

Test plan

  • Unit tests for load_role_assignments_by_user_ids covering empty input, grouped results, missing users, and input order preservation
  • pants fmt fix lint passes
  • pants check (mypy) passes
  • pants test passes

Resolves BA-4814


📚 Documentation preview 📚: https://sorna--9552.org.readthedocs.build/en/9552/


📚 Documentation preview 📚: https://sorna-ko--9552.org.readthedocs.build/ko/9552/

…user

Add a DataLoader to prevent N+1 query issues when loading role
assignments per user. Includes a new `my_roles` field on UserV2GQL
that leverages the loader for efficient batched fetching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 1, 2026 05:32
@github-actions github-actions bot added size:L 100~500 LoC comp:manager Related to Manager component labels Mar 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new RBAC-focused DataLoader and GraphQL field to batch-load role assignments by user ID, reducing N+1 queries when resolving user role assignments.

Changes:

  • Add load_role_assignments_by_user_ids() DataLoader helper that returns role assignments grouped per requested user ID.
  • Register role_assignments_by_user_loader in the central DataLoaders registry.
  • Add AssignedUserConditions.by_user_ids() query condition and expose a new UserV2GQL.my_roles field backed by the DataLoader.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/manager/api/rbac/test_dataloader.py Adds unit tests validating grouping, missing users, empty input, and order preservation for the new loader.
src/ai/backend/manager/repositories/permission_controller/options.py Introduces AssignedUserConditions.by_user_ids() for multi-user filtering.
src/ai/backend/manager/api/gql/user/types/node.py Adds UserV2GQL.my_roles field that resolves via the new DataLoader.
src/ai/backend/manager/api/gql/data_loader/rbac/loader.py Implements load_role_assignments_by_user_ids() batching and grouping logic.
src/ai/backend/manager/api/gql/data_loader/rbac/init.py Exports the new loader function.
src/ai/backend/manager/api/gql/data_loader/data_loaders.py Registers role_assignments_by_user_loader in the DataLoaders registry.

Review notes:

  • The new UserV2GQL.my_roles field name suggests “current viewer’s roles”, but it actually returns assignments for whatever UserV2GQL node is being resolved (and the return type is RoleAssignmentGQL, not RoleGQL). Consider renaming the field (e.g., role_assignments/roles) to match semantics and avoid API confusion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: octodog <mu001@lablup.com>
@github-actions github-actions bot added the area:docs Documentations label Mar 1, 2026
@fregataa fregataa marked this pull request as draft March 1, 2026 05:52
fregataa and others added 2 commits March 1, 2026 14:57
The my_roles field on UserV2GQL is out of scope for BA-4814 (DataLoader only).
This keeps the PR focused on the DataLoader implementation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: octodog <mu001@lablup.com>
@fregataa fregataa marked this pull request as ready for review March 1, 2026 09:04
@fregataa fregataa requested a review from a team March 1, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentations comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants