Conversation
…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>
Contributor
There was a problem hiding this comment.
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_loaderin the centralDataLoadersregistry. - Add
AssignedUserConditions.by_user_ids()query condition and expose a newUserV2GQL.my_rolesfield 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_rolesfield name suggests “current viewer’s roles”, but it actually returns assignments for whateverUserV2GQLnode is being resolved (and the return type isRoleAssignmentGQL, notRoleGQL). 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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
load_role_assignments_by_user_idsDataLoader function for batched loading of role assignments grouped by user IDrole_assignments_by_user_loaderin the centralDataLoadersregistrymy_rolesfield toUserV2GQLthat uses the new DataLoader to prevent N+1 queriesAssignedUserConditions.by_user_ids()query condition for filtering by multiple user IDsTest plan
load_role_assignments_by_user_idscovering empty input, grouped results, missing users, and input order preservationpants fmt fix lintpassespants check(mypy) passespants testpassesResolves BA-4814
📚 Documentation preview 📚: https://sorna--9552.org.readthedocs.build/en/9552/
📚 Documentation preview 📚: https://sorna-ko--9552.org.readthedocs.build/ko/9552/