perf: avoid redundant knowledge re-fetch in update_knowledge_access_by_id (#23799)

After set_access_grants, the handler was reloading the same knowledge
record via get_knowledge_by_id, which triggers an extra SELECT plus a
nested fetch of access grants. set_access_grants already returns the
newly-written grants and the local knowledge object is otherwise
unchanged, so update it in place and reuse it for the response.

https://claude.ai/code/session_01S18Lgqbih7Ry2JZUUv8TxF

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Classic298
2026-04-17 14:44:42 +09:00
committed by GitHub
co-authored by Claude
parent 55bfc7cbc2
commit f0e0cfcf02
+4 -2
View File
@@ -539,10 +539,12 @@ async def update_knowledge_access_by_id(
'sharing.public_knowledge',
)
await AccessGrants.set_access_grants('knowledge', id, form_data.access_grants, db=db)
knowledge.access_grants = await AccessGrants.set_access_grants(
'knowledge', id, form_data.access_grants, db=db
)
return KnowledgeFilesResponse(
**(await Knowledges.get_knowledge_by_id(id=id, db=db)).model_dump(),
**knowledge.model_dump(),
files=await Knowledges.get_file_metadatas_by_id(id, db=db),
)