Skip to content

Commit 085b8c7

Browse files
committed
fixes test and refactor query
1 parent 639e507 commit 085b8c7

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ class ProjectGet(OutputSchema):
110110

111111
@classmethod
112112
def from_domain_model(cls, project_data: dict[str, Any]) -> Self:
113-
data = copy.copy(project_data)
113+
trimmed_data = copy.copy(project_data)
114114
# project_data["trashed_by"] is a UserID
115115
# project_data["trashed_by_primary_gid"] is a GroupID
116-
data.pop("trashed_by", None)
117-
data.pop("trashedBy", None)
116+
trimmed_data.pop("trashed_by", None)
117+
trimmed_data.pop("trashedBy", None)
118118

119119
return cls.model_validate(
120120
remap_keys(
121-
project_data,
121+
trimmed_data,
122122
rename={
123123
"trashed": "trashed_at",
124124
"trashed_by_primary_gid": "trashed_by",

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -571,18 +571,20 @@ async def get_folders_recursively(
571571
return cast(list[FolderID], [row.folder_id async for row in result])
572572

573573

574+
def _select_trashed_by_primary_gid_query():
575+
return sa.select(users.c.primary_gid.label("trashed_by_primary_gid")).select_from(
576+
folders_v2.outerjoin(users, folders_v2.c.trashed_by == users.c.id),
577+
)
578+
579+
574580
async def get_trashed_by_primary_gid(
575581
app: web.Application,
576582
connection: AsyncConnection | None = None,
577583
*,
578584
folder_id: FolderID,
579585
) -> GroupID | None:
580-
query = (
581-
sa.select(
582-
users.c.primary_gid.label("trashed_by_primary_gid"),
583-
)
584-
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
585-
.where(folders_v2.c.folder_id == folder_id)
586+
query = _select_trashed_by_primary_gid_query().where(
587+
folders_v2.c.folder_id == folder_id
586588
)
587589

588590
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
@@ -599,11 +601,9 @@ async def batch_get_trashed_by_primary_gid(
599601
) -> list[GroupID | None]:
600602

601603
query = (
602-
sa.select(
603-
users.c.primary_gid.label("trashed_by_primary_gid"),
604+
_select_trashed_by_primary_gid_query().where(
605+
folders_v2.c.folder_id.in_(folders_ids)
604606
)
605-
.select_from(folders_v2.outerjoin(users, folders_v2.c.trashed_by == users.c.id))
606-
.where(folders_v2.c.folder_id.in_(folders_ids))
607607
).order_by(
608608
*[
609609
folders_v2.c.folder_id == _id for _id in folders_ids

services/web/server/src/simcore_service_webserver/projects/_projects_db.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ async def patch_project(
5050
return ProjectDB.model_validate(row)
5151

5252

53+
def _select_trashed_by_primary_gid_query():
54+
return sa.select(
55+
users.c.primary_gid.label("trashed_by_primary_gid"),
56+
).select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
57+
58+
5359
async def get_trashed_by_primary_gid(
5460
app: web.Application,
5561
connection: AsyncConnection | None = None,
5662
*,
5763
projects_uuid: ProjectID,
5864
) -> GroupID | None:
59-
query = (
60-
sa.select(
61-
users.c.primary_gid.label("trashed_by_primary_gid"),
62-
)
63-
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
64-
.where(projects.c.uuid == projects_uuid)
65+
query = _select_trashed_by_primary_gid_query().where(
66+
projects.c.uuid == projects_uuid
6567
)
6668

6769
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
@@ -87,11 +89,9 @@ async def batch_get_trashed_by_primary_gid(
8789
projects_uuids_str = [f"{uuid}" for uuid in projects_uuids]
8890

8991
query = (
90-
sa.select(
91-
users.c.primary_gid.label("trashed_by_primary_gid"),
92+
_select_trashed_by_primary_gid_query().where(
93+
projects.c.uuid.in_(projects_uuids_str)
9294
)
93-
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
94-
.where(projects.c.uuid.in_(projects_uuids_str))
9595
).order_by(
9696
*[
9797
projects.c.uuid == uuid for uuid in projects_uuids_str

0 commit comments

Comments
 (0)