Skip to content

Commit 363ad0d

Browse files
committed
@sanderegg review: interfaces for batch/ update
1 parent 66aca04 commit 363ad0d

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

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

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,9 @@ async def get_for_user_or_workspace(
213213
return FolderDB.from_orm(row)
214214

215215

216-
_MAX_ITEMS_UPDATE: Final = 100
217-
218-
219-
async def update(
216+
async def _update_impl(
220217
app: web.Application,
221-
*,
222-
folder_id: FolderID | set[FolderID],
218+
folders_id_or_ids: FolderID | set[FolderID],
223219
product_name: ProductName,
224220
# updatable columns
225221
name: str | UnSet = _unset,
@@ -244,25 +240,64 @@ async def update(
244240
.returning(*_SELECTION_ARGS)
245241
)
246242

247-
if isinstance(folder_id, set):
248-
if len(folder_id) == 0 or len(folder_id) > _MAX_ITEMS_UPDATE:
249-
msg = f"Number of items for batch update is out-of-range, got {len(folder_id)=}"
250-
raise ValueError(msg)
251-
243+
if isinstance(folders_id_or_ids, set):
252244
# batch-update
253-
query = query.where(folders_v2.c.folder_id.in_(list(folder_id)))
245+
query = query.where(folders_v2.c.folder_id.in_(list(folders_id_or_ids)))
254246
else:
255247
# single-update
256-
query = query.where(folders_v2.c.folder_id == folder_id)
248+
query = query.where(folders_v2.c.folder_id == folders_id_or_ids)
257249

258250
async with get_database_engine(app).acquire() as conn:
259251
result = await conn.execute(query)
260252
row = await result.first()
261253
if row is None:
262-
raise FolderNotFoundError(reason=f"Folder {folder_id} not found.")
254+
raise FolderNotFoundError(reason=f"Folder {folders_id_or_ids} not found.")
263255
return FolderDB.from_orm(row)
264256

265257

258+
async def update_batch(
259+
app: web.Application,
260+
*folder_id: FolderID,
261+
product_name: ProductName,
262+
# updatable columns
263+
name: str | UnSet = _unset,
264+
parent_folder_id: FolderID | None | UnSet = _unset,
265+
trashed_at: datetime | None | UnSet = _unset,
266+
trashed_explicitly: bool | UnSet = _unset,
267+
) -> FolderDB:
268+
return await _update_impl(
269+
app=app,
270+
folders_id_or_ids=set(folder_id),
271+
product_name=product_name,
272+
name=name,
273+
parent_folder_id=parent_folder_id,
274+
trashed_at=trashed_at,
275+
trashed_explicitly=trashed_explicitly,
276+
)
277+
278+
279+
async def update(
280+
app: web.Application,
281+
*,
282+
folder_id: FolderID,
283+
product_name: ProductName,
284+
# updatable columns
285+
name: str | UnSet = _unset,
286+
parent_folder_id: FolderID | None | UnSet = _unset,
287+
trashed_at: datetime | None | UnSet = _unset,
288+
trashed_explicitly: bool | UnSet = _unset,
289+
) -> FolderDB:
290+
return await _update_impl(
291+
app=app,
292+
folders_id_or_ids=folder_id,
293+
product_name=product_name,
294+
name=name,
295+
parent_folder_id=parent_folder_id,
296+
trashed_at=trashed_at,
297+
trashed_explicitly=trashed_explicitly,
298+
)
299+
300+
266301
async def delete_recursively(
267302
app: web.Application,
268303
*,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ async def _batch_update_folders(
7575
}
7676

7777
if child_folders:
78-
await _folders_db.update(
78+
await _folders_db.update_batch(
7979
app,
80-
folder_id=child_folders,
80+
*child_folders,
8181
product_name=product_name,
8282
trashed_at=trashed_at,
8383
trashed_explicitly=False,

0 commit comments

Comments
 (0)