Skip to content

Commit d980e30

Browse files
committed
initial AI stupid
1 parent 015b1d8 commit d980e30

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

services/web/server/src/simcore_service_webserver/functions/_functions_repository.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,16 +1032,18 @@ async def get_user_api_access_rights(
10321032
user_id: UserID,
10331033
product_name: ProductName,
10341034
) -> FunctionUserApiAccessRights:
1035-
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
1035+
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
10361036
user_groups = await list_all_user_groups_ids(app, user_id=user_id)
10371037

1038-
result = await conn.stream(
1039-
funcapi_api_access_rights_table.select().where(
1040-
funcapi_api_access_rights_table.c.group_id.in_(user_groups),
1041-
funcapi_api_access_rights_table.c.product_name == product_name,
1038+
rows = [
1039+
row
1040+
async for row in await conn.stream(
1041+
funcapi_api_access_rights_table.select().where(
1042+
funcapi_api_access_rights_table.c.group_id.in_(user_groups),
1043+
funcapi_api_access_rights_table.c.product_name == product_name,
1044+
)
10421045
)
1043-
)
1044-
rows = await result.all()
1046+
]
10451047
if not rows:
10461048
return FunctionUserApiAccessRights(user_id=user_id)
10471049
combined_permissions = {
@@ -1074,7 +1076,7 @@ async def get_user_permissions(
10741076
object_id: UUID,
10751077
object_type: Literal["function", "function_job", "function_job_collection"],
10761078
) -> FunctionAccessRightsDB | None:
1077-
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
1079+
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
10781080
await check_exists(
10791081
app,
10801082
conn,
@@ -1097,7 +1099,7 @@ async def get_user_permissions(
10971099

10981100
user_groups = await list_all_user_groups_ids(app, user_id=user_id)
10991101

1100-
# Combine permissions for all groups the user belongs to
1102+
# Collect rows using streaming to efficiently handle permissions
11011103
result = await conn.stream(
11021104
access_rights_table.select()
11031105
.with_only_columns(*cols)
@@ -1107,7 +1109,7 @@ async def get_user_permissions(
11071109
access_rights_table.c.group_id.in_(user_groups),
11081110
)
11091111
)
1110-
rows = await result.all()
1112+
rows = [row async for row in result]
11111113

11121114
if not rows:
11131115
return None

0 commit comments

Comments
 (0)