perf: halve function-table queries in get_all_models (#27230)

get_all_models ran four function-table queries: global actions, active
actions, global filters, active filters. Global functions are by
definition (type, is_active=True, is_global=True) — a subset of the
active set — so the global id sets can be derived from the active-rows
queries' is_global flag. Four queries become two, and each dropped
query returned full rows including every plugin's source code.

Also folds the mid-function 'models.default_metadata' read into the
Config.get_many already issued at the top of the function (one fewer
round trip; the existing `or {}` default handling is preserved).


Claude-Session: https://claude.ai/code/session_01MHg5zs1VBjvRWQ54qHpfYD

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Classic298
2026-07-23 12:11:51 -04:00
committed by GitHub
co-authored by Claude
parent 32242a6788
commit 9a54bc4bbb
+16 -17
View File
@@ -68,6 +68,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
'models.base_models_cache', 'models.base_models_cache',
'evaluation.arena.enable', 'evaluation.arena.enable',
'evaluation.arena.models', 'evaluation.arena.models',
'models.default_metadata',
) )
if ( if (
request.app.state.MODELS request.app.state.MODELS
@@ -125,23 +126,21 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
] ]
models = models + arena_models models = models + arena_models
global_action_ids = ( # One query per type: the global sets are subsets of the active sets, so
{function.id for function in await Functions.get_global_action_functions()} if ENABLE_PLUGINS else set() # deriving them from the same rows halves the function-table queries.
) if ENABLE_PLUGINS:
enabled_action_ids = ( active_actions = await Functions.get_functions_by_type('action', active_only=True)
{function.id for function in await Functions.get_functions_by_type('action', active_only=True)} global_action_ids = {function.id for function in active_actions if function.is_global}
if ENABLE_PLUGINS enabled_action_ids = {function.id for function in active_actions}
else set()
)
global_filter_ids = ( active_filters = await Functions.get_functions_by_type('filter', active_only=True)
{function.id for function in await Functions.get_global_filter_functions()} if ENABLE_PLUGINS else set() global_filter_ids = {function.id for function in active_filters if function.is_global}
) enabled_filter_ids = {function.id for function in active_filters}
enabled_filter_ids = ( else:
{function.id for function in await Functions.get_functions_by_type('filter', active_only=True)} global_action_ids = set()
if ENABLE_PLUGINS enabled_action_ids = set()
else set() global_filter_ids = set()
) enabled_filter_ids = set()
custom_models = await Models.get_all_models() custom_models = await Models.get_all_models()
@@ -305,7 +304,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
# Apply global model defaults to all models # Apply global model defaults to all models
# Per-model overrides take precedence over global defaults # Per-model overrides take precedence over global defaults
default_metadata = await Config.get('models.default_metadata', {}) or {} default_metadata = config.get('models.default_metadata') or {}
if default_metadata: if default_metadata:
for model in models: for model in models: