perf: filter workspace models by access in SQL instead of loading every model (#28795)
Exporting workspace models loaded every model row, built a full response object with its owner for each, and only then dropped the ones the caller may not see. On a large model table that made the export endpoint slow in proportion to models the user cannot even access. The owner-or-grant check now happens in the query itself, reusing the permission filter this file already applies to the paginated list endpoint, so only visible rows are ever hydrated. The by-user wrapper had one caller left and is gone with it. Measured with 500 workspace models of which 3 are visible to the caller: 5 queries and ~12.7 ms before, 4 queries and ~2.8 ms after. The resulting set is unchanged for owner, public, direct-user, group and multi-grant entries, and base model entries stay excluded as before.
This commit is contained in:
@@ -353,7 +353,7 @@ async def export_models(
|
||||
if user.role == 'admin' and BYPASS_ADMIN_ACCESS_CONTROL:
|
||||
return await Models.get_models(db=db)
|
||||
else:
|
||||
return await Models.get_models_by_user_id(user.id, db=db)
|
||||
return await Models.get_models(writable_by_user_id=user.id, db=db)
|
||||
|
||||
|
||||
############################
|
||||
|
||||
Reference in New Issue
Block a user