The prompts listing endpoints were calling _get_access_grants() per
prompt (N+1 queries) via _to_prompt_model(). Additionally,
get_prompts_by_user_id() called has_access() per prompt for filtering
(another N+1). Now:
- get_prompts() batch-fetches all access grants in one query via new
get_grants_by_resources() method on AccessGrants
- get_prompts_by_user_id() uses batch get_accessible_resource_ids()
instead of per-prompt has_access() calls
- search_prompts() batch-fetches grants instead of per-item
_to_prompt_model() calls
For 30 prompts this reduces ~31 DB queries to ~3.
The prompts listing endpoints were calling _get_access_grants() per
prompt (N+1 queries) via _to_prompt_model(). Additionally,
get_prompts_by_user_id() called has_access() per prompt for filtering
(another N+1). Now:
get_grants_by_resources() method on AccessGrants
instead of per-prompt has_access() calls
_to_prompt_model() calls
For 30 prompts this reduces ~31 DB queries to ~3.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.