refac
This commit is contained in:
@@ -290,6 +290,18 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||
function_module, _, _ = get_function_module_from_cache(request, function_id)
|
||||
return function_module
|
||||
|
||||
# Batch-prefetch all needed function IDs to avoid N+1 queries
|
||||
all_function_ids = set()
|
||||
for model in models:
|
||||
all_function_ids.update(model.get("action_ids", []))
|
||||
all_function_ids.update(model.get("filter_ids", []))
|
||||
all_function_ids.update(global_action_ids)
|
||||
all_function_ids.update(global_filter_ids)
|
||||
|
||||
functions_by_id = {
|
||||
f.id: f for f in Functions.get_functions_by_ids(list(all_function_ids))
|
||||
}
|
||||
|
||||
for model in models:
|
||||
action_ids = [
|
||||
action_id
|
||||
@@ -304,7 +316,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||
|
||||
model["actions"] = []
|
||||
for action_id in action_ids:
|
||||
action_function = Functions.get_function_by_id(action_id)
|
||||
action_function = functions_by_id.get(action_id)
|
||||
if action_function is None:
|
||||
raise Exception(f"Action not found: {action_id}")
|
||||
|
||||
@@ -315,7 +327,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||
|
||||
model["filters"] = []
|
||||
for filter_id in filter_ids:
|
||||
filter_function = Functions.get_function_by_id(filter_id)
|
||||
filter_function = functions_by_id.get(filter_id)
|
||||
if filter_function is None:
|
||||
raise Exception(f"Filter not found: {filter_id}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user