Skip to content

Commit 6612f29

Browse files
committed
working
1 parent 221a482 commit 6612f29

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,8 @@ async def list_paths(
245245
return paths_metadata, next_cursor, total
246246

247247
async def compute_path_total_size(self, user_id: UserID, *, path: Path) -> ByteSize:
248-
"""returns the total size of the path"""
249-
250-
# check access rights
248+
"""returns the total size of an arbitrary path"""
249+
# check access rights first
251250
project_id = None
252251
with contextlib.suppress(ValueError):
253252
# NOTE: we currently do not support anything else than project_id/node_id/file_path here, sorry chap
@@ -257,30 +256,31 @@ async def compute_path_total_size(self, user_id: UserID, *, path: Path) -> ByteS
257256
conn, user_id=user_id, project_id=project_id
258257
)
259258

260-
# compute the total size (files and base folders are in the DB)
261259
# use-cases:
262-
# 1. path is partial and smaller than in the DB --> all entries are in the DB (files and folder) sum will be done there
263-
# 2. path is partial and not in the DB --> entries are in S3, list the entries and sum their sizes
264-
# 3. path is complete and in the DB --> return directly from the DB
265-
# 4. path is complete and not in the DB --> entry in S3, returns directly from there
260+
# 1. path is not a valid StorageFileID (e.g. a project or project/node) --> all entries are in the DB (files and folder)
261+
# 2. path is valid StorageFileID and not in the DB --> entries are only in S3
262+
# 3. path is valid StorageFileID and in the DB --> return directly from the DB
266263

264+
use_db_data = True
267265
with contextlib.suppress(ValidationError):
268266
file_id = TypeAdapter(StorageFileID).validate_python(f"{path}")
269-
# path might be complete
270-
with contextlib.suppress(FileMetaDataNotFoundError):
271-
# file or folder is in DB
272-
async with self.engine.connect() as conn:
273-
fmd = await file_meta_data.get(conn, file_id=file_id)
274-
assert isinstance(fmd.file_size, ByteSize) # nosec
275-
return fmd.file_size
276-
# file or folder is in S3
267+
# path is a valid StorageFileID
268+
async with self.engine.connect() as conn:
269+
if (
270+
dir_fmd := await file_meta_data.try_get_directory(conn, path)
271+
) and dir_fmd.file_id != file_id:
272+
# this is pure S3 aka use-case 2
273+
use_db_data = False
274+
275+
if not use_db_data:
276+
assert file_id # nosec
277277
s3_metadata = await get_s3_client(self.app).get_directory_metadata(
278278
bucket=self.simcore_bucket_name, prefix=file_id
279279
)
280280
assert s3_metadata.size # nosec
281281
return s3_metadata.size
282282

283-
# path is partial not containing the minimal requirements to be a fully fledged file_id (only 1 or 2 parts), so everything is in DB
283+
# all other use-cases are in the DB
284284
async with self.engine.connect() as conn:
285285
fmds = await file_meta_data.list_filter_with_partial_file_id(
286286
conn,
@@ -293,7 +293,7 @@ async def compute_path_total_size(self, user_id: UserID, *, path: Path) -> ByteS
293293
is_directory=None,
294294
)
295295

296-
# ensure file sizes are uptodate
296+
# ensure file sizes are uptodate
297297
updated_fmds = []
298298
for metadata in fmds:
299299
if is_file_entry_valid(metadata):
@@ -759,9 +759,9 @@ async def deep_copy_project_simcore_s3(
759759
task_progress, f"Collecting files of '{src_project['name']}'..."
760760
)
761761
async with self.engine.connect() as conn:
762-
src_project_files: list[
763-
FileMetaDataAtDB
764-
] = await file_meta_data.list_fmds(conn, project_ids=[src_project_uuid])
762+
src_project_files: list[FileMetaDataAtDB] = (
763+
await file_meta_data.list_fmds(conn, project_ids=[src_project_uuid])
764+
)
765765

766766
with log_context(
767767
_logger,
@@ -875,19 +875,19 @@ async def search_owned_files(
875875
offset: int | None = None,
876876
) -> list[FileMetaData]:
877877
async with self.engine.connect() as conn:
878-
file_metadatas: list[
879-
FileMetaDataAtDB
880-
] = await file_meta_data.list_filter_with_partial_file_id(
881-
conn,
882-
user_or_project_filter=UserOrProjectFilter(
883-
user_id=user_id, project_ids=[]
884-
),
885-
file_id_prefix=file_id_prefix,
886-
partial_file_id=None,
887-
is_directory=False,
888-
sha256_checksum=sha256_checksum,
889-
limit=limit,
890-
offset=offset,
878+
file_metadatas: list[FileMetaDataAtDB] = (
879+
await file_meta_data.list_filter_with_partial_file_id(
880+
conn,
881+
user_or_project_filter=UserOrProjectFilter(
882+
user_id=user_id, project_ids=[]
883+
),
884+
file_id_prefix=file_id_prefix,
885+
partial_file_id=None,
886+
is_directory=False,
887+
sha256_checksum=sha256_checksum,
888+
limit=limit,
889+
offset=offset,
890+
)
891891
)
892892
resolved_fmds = []
893893
for fmd in file_metadatas:

0 commit comments

Comments
 (0)