-
Notifications
You must be signed in to change notification settings - Fork 178
feat(BA-6810): AppConfigFragment visible-fragments query (repository layer) #12706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add the AppConfigFragment visible-fragments repository query: fetch the public / domain / user fragments visible to a (domain, user) principal for one or many config names, rank-ordered via the allow-list, in a single query. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,12 +21,18 @@ | |
| from ai.backend.manager.errors.app_config import ( | ||
| AppConfigFragmentNotFound, | ||
| ) | ||
| from ai.backend.manager.models.app_config_allow_list.row import AppConfigAllowListRow | ||
| from ai.backend.manager.models.app_config_fragment.conditions import AppConfigFragmentConditions | ||
| from ai.backend.manager.models.app_config_fragment.row import AppConfigFragmentRow | ||
| from ai.backend.manager.models.scopes import SearchScope | ||
| from ai.backend.manager.repositories.app_config_fragment.types import ( | ||
| AppConfigScopeArguments, | ||
| ) | ||
| from ai.backend.manager.repositories.base import ( | ||
| BatchQuerier, | ||
| BulkCreator, | ||
| Creator, | ||
| NoPagination, | ||
| Purger, | ||
| Querier, | ||
| Updater, | ||
|
|
@@ -193,3 +199,44 @@ async def scoped_search( | |
| has_next_page=result.has_next_page, | ||
| has_previous_page=result.has_previous_page, | ||
| ) | ||
|
|
||
| @app_config_fragment_db_source_resilience.apply() | ||
| async def list_visible_fragments_bulk( | ||
| self, config_names: list[str], scope: AppConfigScopeArguments | ||
| ) -> list[AppConfigFragmentData]: | ||
| """Visible fragments for several ``config_names`` at once, in a single query. | ||
|
|
||
| Selects the requested names AND any one of the principal's visible scopes (public, | ||
| its domain, or its own user). The scope filter is name-independent, so it is a single | ||
| OR group AND-combined with the name membership. Merge priority (``rank``) lives on the | ||
| joined allow-list entry; the result is always ordered by ascending ``rank`` so the | ||
| caller can group by name (each name's subset stays rank-ordered) and deep-merge each | ||
| name's fragments in order. | ||
| """ | ||
| if not config_names: | ||
| return [] | ||
| scope_visibility = [ | ||
| AppConfigFragmentConditions.by_public_visibility(), | ||
| AppConfigFragmentConditions.by_domain_visibility(str(scope.domain_id)), | ||
| AppConfigFragmentConditions.by_user_visibility(str(scope.user_id)), | ||
|
Comment on lines
+218
to
+221
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seem necessary to manage this as a separate variable. |
||
| ] | ||
| querier = BatchQuerier( | ||
| pagination=NoPagination(), | ||
| conditions=[ | ||
| AppConfigFragmentConditions.by_config_names(config_names), | ||
| lambda: sa.or_(*(visibility() for visibility in scope_visibility)), | ||
| ], | ||
| orders=[AppConfigAllowListRow.rank.asc()], | ||
| ) | ||
| # Join each fragment to its allow-list entry (indexed ``(config_name, scope_type)`` FK | ||
| # pair), which carries the merge ``rank`` the result is ordered by. | ||
| selector = sa.select(AppConfigFragmentRow).join( | ||
| AppConfigAllowListRow, | ||
| sa.and_( | ||
| AppConfigAllowListRow.config_name == AppConfigFragmentRow.config_name, | ||
| AppConfigAllowListRow.scope_type == AppConfigFragmentRow.scope_type, | ||
| ), | ||
| ) | ||
|
Comment on lines
+231
to
+239
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the "join" unnecessary? |
||
| async with self._ops.read_ops() as r: | ||
| result = await r.batch_query_in_global(selector, querier) | ||
| return [row.AppConfigFragmentRow.to_data() for row in result.rows] | ||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you decide that managing it this way is better than generalizing it into a single condition? (Iβm asking just to confirm, since this seems like a design choice.)