Skip to content

Commit 64f4337

Browse files
committed
GitHK review: add stream in all operations that return
1 parent a65fb67 commit 64f4337

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

services/web/server/src/simcore_service_webserver/folders/_folders_db.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def create(
7474
), "Both user_id and workspace_id cannot be provided at the same time. Please provide only one."
7575

7676
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
77-
result = await conn.execute(
77+
result = await conn.stream(
7878
folders_v2.insert()
7979
.values(
8080
name=folder_name,
@@ -88,7 +88,7 @@ async def create(
8888
)
8989
.returning(*_SELECTION_ARGS)
9090
)
91-
row = result.first()
91+
row = await result.first()
9292
return FolderDB.from_orm(row)
9393

9494

@@ -174,8 +174,8 @@ async def get(
174174
)
175175

176176
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
177-
result = await conn.execute(query)
178-
row = result.first()
177+
result = await conn.stream(query)
178+
row = await result.first()
179179
if row is None:
180180
raise FolderAccessForbiddenError(
181181
reason=f"Folder {folder_id} does not exist.",
@@ -211,8 +211,8 @@ async def get_for_user_or_workspace(
211211
query = query.where(folders_v2.c.workspace_id == workspace_id)
212212

213213
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
214-
result = await conn.execute(query)
215-
row = result.first()
214+
result = await conn.stream(query)
215+
row = await result.first()
216216
if row is None:
217217
raise FolderAccessForbiddenError(
218218
reason=f"User does not have access to the folder {folder_id}. Or folder does not exist.",
@@ -257,8 +257,8 @@ async def update(
257257
query = query.where(folders_v2.c.folder_id == folders_id_or_ids)
258258

259259
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
260-
result = await conn.execute(query)
261-
row = result.first()
260+
result = await conn.stream(query)
261+
row = await result.first()
262262
if row is None:
263263
raise FolderNotFoundError(reason=f"Folder {folders_id_or_ids} not found.")
264264
return FolderDB.from_orm(row)

services/web/server/src/simcore_service_webserver/workspaces/_groups_db.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def create_workspace_group(
5555
delete: bool,
5656
) -> WorkspaceGroupGetDB:
5757
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
58-
result = await conn.execute(
58+
result = await conn.stream(
5959
workspaces_access_rights.insert()
6060
.values(
6161
workspace_id=workspace_id,
@@ -68,7 +68,7 @@ async def create_workspace_group(
6868
)
6969
.returning(literal_column("*"))
7070
)
71-
row = result.first()
71+
row = await result.first()
7272
return WorkspaceGroupGetDB.from_orm(row)
7373

7474

@@ -120,8 +120,8 @@ async def get_workspace_group(
120120
)
121121

122122
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
123-
result = await conn.execute(stmt)
124-
row = result.first()
123+
result = await conn.stream(stmt)
124+
row = await result.first()
125125
if row is None:
126126
raise WorkspaceGroupNotFoundError(
127127
workspace_id=workspace_id, group_id=group_id
@@ -140,7 +140,7 @@ async def update_workspace_group(
140140
delete: bool,
141141
) -> WorkspaceGroupGetDB:
142142
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
143-
result = await conn.execute(
143+
result = await conn.stream(
144144
workspaces_access_rights.update()
145145
.values(
146146
read=read,
@@ -153,7 +153,7 @@ async def update_workspace_group(
153153
)
154154
.returning(literal_column("*"))
155155
)
156-
row = result.first()
156+
row = await result.first()
157157
if row is None:
158158
raise WorkspaceGroupNotFoundError(
159159
workspace_id=workspace_id, group_id=group_id

services/web/server/src/simcore_service_webserver/workspaces/_workspaces_db.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def create_workspace(
5959
thumbnail: str | None,
6060
) -> WorkspaceDB:
6161
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
62-
result = await conn.execute(
62+
result = await conn.stream(
6363
workspaces.insert()
6464
.values(
6565
name=name,
@@ -72,7 +72,7 @@ async def create_workspace(
7272
)
7373
.returning(*_SELECTION_ARGS)
7474
)
75-
row = result.first()
75+
row = await result.first()
7676
return WorkspaceDB.from_orm(row)
7777

7878

@@ -157,8 +157,7 @@ async def list_workspaces_for_user(
157157
list_query = list_query.offset(offset).limit(limit)
158158

159159
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
160-
count_result = await conn.execute(count_query)
161-
total_count = count_result.scalar()
160+
total_count = await conn.scalar(count_query)
162161

163162
result = await conn.stream(list_query)
164163
items: list[UserWorkspaceAccessRightsDB] = [
@@ -194,8 +193,8 @@ async def get_workspace_for_user(
194193
)
195194

196195
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
197-
result = await conn.execute(base_query)
198-
row = result.first()
196+
result = await conn.stream(base_query)
197+
row = await result.first()
199198
if row is None:
200199
raise WorkspaceAccessForbiddenError(
201200
reason=f"User {user_id} does not have access to the workspace {workspace_id}. Or workspace does not exist.",
@@ -214,7 +213,7 @@ async def update_workspace(
214213
product_name: ProductName,
215214
) -> WorkspaceDB:
216215
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
217-
result = await conn.execute(
216+
result = await conn.stream(
218217
workspaces.update()
219218
.values(
220219
name=name,
@@ -228,7 +227,7 @@ async def update_workspace(
228227
)
229228
.returning(*_SELECTION_ARGS)
230229
)
231-
row = result.first()
230+
row = await result.first()
232231
if row is None:
233232
raise WorkspaceNotFoundError(reason=f"Workspace {workspace_id} not found.")
234233
return WorkspaceDB.from_orm(row)

0 commit comments

Comments
 (0)