Skip to content

Commit d612a58

Browse files
update implementation
1 parent 27c9462 commit d612a58

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,17 @@ async def __get_link(
499499

500500
return link
501501

502-
def find_enclosing(self, file_id: str, kwnown_file_ids: list[str]) -> str | None:
502+
async def __find_enclosing_file(
503+
self, conn: SAConnection, user_id: UserID, file_id: SimcoreS3FileID
504+
) -> FileMetaDataAtDB | None:
505+
kwnon_files = {
506+
Path(known_file.file_id): known_file
507+
for known_file in await db_file_meta_data.list_fmds(conn, user_id=user_id)
508+
}
503509
current_path = Path(file_id)
504-
kwnon_file_paths = [Path(file_id) for file_id in kwnown_file_ids]
505-
506510
while current_path and current_path != Path(current_path).parent:
507-
if current_path in kwnon_file_paths:
508-
return f"{current_path}"
511+
if current_path in kwnon_files:
512+
return kwnon_files.get(current_path)
509513

510514
current_path = Path(current_path).parent
511515

@@ -535,33 +539,14 @@ async def delete_file(
535539
if not can.delete:
536540
raise FileAccessRightError(access_right="delete", file_id=file_id)
537541

538-
# NOTE: deleting might be slow, so better ensure we release the connection
539-
async with self.engine.acquire() as conn:
540-
enclosing_file_id = self.find_enclosing(
541-
file_id,
542-
[
543-
known_file.file_id
544-
for known_file in await db_file_meta_data.list_fmds(
545-
conn, user_id=user_id
546-
)
547-
],
548-
)
549-
550-
enclosing_file = await db_file_meta_data.get(
551-
conn, TypeAdapter(SimcoreS3FileID).validate_python(enclosing_file_id)
552-
)
553-
554-
if await db_file_meta_data.exists(conn, file_id):
542+
enclosing_file = await self.__find_enclosing_file(conn, user_id, file_id)
543+
if enclosing_file and enclosing_file.file_id == file_id:
555544
await db_file_meta_data.delete(conn, [file_id])
556545

557-
await get_s3_client(self.app).delete_objects_recursively(
558-
bucket=enclosing_file.bucket_name,
559-
prefix=(
560-
ensure_ends_with(enclosing_file.file_id, "/")
561-
if enclosing_file.is_directory and enclosing_file_id == file_id
562-
else file_id
563-
),
564-
)
546+
await get_s3_client(self.app).delete_objects_recursively(
547+
bucket=self.simcore_bucket_name,
548+
prefix=file_id,
549+
)
565550

566551
async def delete_project_simcore_s3(
567552
self, user_id: UserID, project_id: ProjectID, node_id: NodeID | None = None

0 commit comments

Comments
 (0)