File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
services/web/server/src/simcore_service_webserver Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -599,18 +599,22 @@ async def batch_get_trashed_by_primary_gid(
599599 * ,
600600 folders_ids : list [FolderID ],
601601) -> list [GroupID | None ]:
602+ if not folders_ids :
603+ return []
602604
603605 query = (
604606 _select_trashed_by_primary_gid_query ().where (
605607 folders_v2 .c .folder_id .in_ (folders_ids )
606608 )
607609 ).order_by (
608- * [
609- folders_v2 .c .folder_id == _id for _id in folders_ids
610- ] # Preserves the order of folders_ids
610+ # Preserves the order of folders_ids
611+ # SEE https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.case
612+ sa .case (
613+ {folder_id : index for index , folder_id in enumerate (folders_ids )},
614+ value = folders_v2 .c .folder_id ,
615+ )
611616 )
612617
613618 async with pass_or_acquire_connection (get_asyncpg_engine (app ), connection ) as conn :
614- result = await conn .execute (query )
615- rows = result .fetchall ()
616- return [row .trashed_by_primary_gid for row in rows ]
619+ result = await conn .stream (query )
620+ return [row .trashed_by_primary_gid async for row in result ]
Original file line number Diff line number Diff line change @@ -93,9 +93,15 @@ async def batch_get_trashed_by_primary_gid(
9393 projects .c .uuid .in_ (projects_uuids_str )
9494 )
9595 ).order_by (
96- * [
97- projects .c .uuid == uuid for uuid in projects_uuids_str
98- ] # Preserves the order of project_uuids
96+ # Preserves the order of folders_ids
97+ # SEE https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.case
98+ sa .case (
99+ {
100+ project_uuid : index
101+ for index , project_uuid in enumerate (projects_uuids_str )
102+ },
103+ value = projects .c .uuid ,
104+ )
99105 )
100106 async with pass_or_acquire_connection (get_asyncpg_engine (app ), connection ) as conn :
101107 result = await conn .stream (query )
You can’t perform that action at this time.
0 commit comments