Skip to content

Commit 626b08a

Browse files
committed
drops history from listing in catalog
1 parent ecd2694 commit 626b08a

File tree

12 files changed

+137
-209
lines changed

12 files changed

+137
-209
lines changed

packages/models-library/src/models_library/api_schemas_catalog/services.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,15 @@ class _BaseServiceGetV2(CatalogOutputSchema):
202202

203203
access_rights: dict[GroupID, ServiceGroupAccessRightsV2] | None
204204

205-
classifiers: list[str] | None = []
206-
quality: dict[str, Any] = {}
205+
classifiers: Annotated[
206+
list[str] | None,
207+
Field(default_factory=list),
208+
] = DEFAULT_FACTORY
209+
210+
quality: Annotated[
211+
dict[str, Any],
212+
Field(default_factory=dict),
213+
] = DEFAULT_FACTORY
207214

208215
model_config = ConfigDict(
209216
extra="forbid",
@@ -212,6 +219,9 @@ class _BaseServiceGetV2(CatalogOutputSchema):
212219
)
213220

214221

222+
class LatestServiceGet(_BaseServiceGetV2): ...
223+
224+
215225
class ServiceGetV2(_BaseServiceGetV2):
216226
# Model used in catalog's rpc and rest interfaces
217227
history: Annotated[
@@ -288,21 +298,9 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
288298
)
289299

290300

291-
class ServiceListItem(_BaseServiceGetV2):
292-
history: Annotated[
293-
list[ServiceRelease],
294-
Field(
295-
default_factory=list,
296-
deprecated=True,
297-
description="History will be replaced by current 'release' instead",
298-
json_schema_extra={"default": []},
299-
),
300-
] = DEFAULT_FACTORY
301-
302-
303301
PageRpcServicesGetV2: TypeAlias = PageRpc[
304302
# WARNING: keep this definition in models_library and not in the RPC interface
305-
ServiceListItem
303+
LatestServiceGet
306304
]
307305

308306
ServiceResourcesGet: TypeAlias = ServiceResourcesDict

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/catalog/services.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from models_library.api_schemas_catalog import CATALOG_RPC_NAMESPACE
77
from models_library.api_schemas_catalog.services import (
8+
LatestServiceGet,
89
MyServiceGet,
910
ServiceGetV2,
10-
ServiceListItem,
1111
ServiceUpdateV2,
1212
)
1313
from models_library.products import ProductName
@@ -35,7 +35,7 @@ async def list_services_paginated( # pylint: disable=too-many-arguments
3535
user_id: UserID,
3636
limit: PageLimitInt = DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
3737
offset: NonNegativeInt = 0,
38-
) -> PageRpc[ServiceListItem]:
38+
) -> PageRpc[LatestServiceGet]:
3939
"""
4040
Raises:
4141
ValidationError: on invalid arguments
@@ -63,9 +63,9 @@ async def _call(
6363
product_name=product_name, user_id=user_id, limit=limit, offset=offset
6464
)
6565
assert ( # nosec
66-
TypeAdapter(PageRpc[ServiceListItem]).validate_python(result) is not None
66+
TypeAdapter(PageRpc[LatestServiceGet]).validate_python(result) is not None
6767
)
68-
return cast(PageRpc[ServiceListItem], result)
68+
return cast(PageRpc[LatestServiceGet], result)
6969

7070

7171
@log_decorator(_logger, level=logging.DEBUG)

services/catalog/src/simcore_service_catalog/api/rpc/_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def list_services_paginated(
6666
) -> PageRpcServicesGetV2:
6767
assert app.state.engine # nosec
6868

69-
total_count, items = await services_api.list_services_paginated(
69+
total_count, items = await services_api.list_latest_services(
7070
repo=ServicesRepository(app.state.engine),
7171
director_api=get_director_api(app),
7272
product_name=product_name,

services/catalog/src/simcore_service_catalog/db/repositories/_services_sql.py

Lines changed: 23 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def list_services_stmt(
3232
combine_access_with_and: bool | None = True,
3333
product_name: str | None = None,
3434
) -> Select:
35-
stmt = sa.select(SERVICES_META_DATA_COLS)
35+
stmt = sa.select(*SERVICES_META_DATA_COLS)
3636
if gids or execute_access or write_access:
3737
conditions: list[Any] = []
3838

@@ -135,7 +135,7 @@ def total_count_stmt(
135135
)
136136

137137

138-
def list_latest_services_with_history_stmt(
138+
def list_latest_services_stmt(
139139
*,
140140
product_name: ProductName,
141141
user_id: UserID,
@@ -174,7 +174,7 @@ def list_latest_services_with_history_stmt(
174174
)
175175

176176
# get all information of latest's services listed in CTE
177-
latest_query = (
177+
latest_stmt = (
178178
sa.select(
179179
services_meta_data.c.key,
180180
services_meta_data.c.version,
@@ -206,126 +206,26 @@ def list_latest_services_with_history_stmt(
206206
.subquery("latest_sq")
207207
)
208208

209-
# get history for every unique service-key in CTE
210-
_accessible_sq = (
211-
sa.select(
212-
services_meta_data.c.key,
213-
services_meta_data.c.version,
214-
)
215-
.distinct()
216-
.select_from(
217-
services_meta_data.join(
218-
cte,
219-
services_meta_data.c.key == cte.c.key,
220-
)
221-
# joins because access-rights might change per version
222-
.join(
223-
services_access_rights,
224-
(services_meta_data.c.key == services_access_rights.c.key)
225-
& (services_meta_data.c.version == services_access_rights.c.version)
226-
& (services_access_rights.c.product_name == product_name),
227-
)
228-
.join(
229-
user_to_groups,
230-
(user_to_groups.c.gid == services_access_rights.c.gid)
231-
& (user_to_groups.c.uid == user_id),
232-
)
233-
.outerjoin(
234-
services_compatibility,
235-
(services_meta_data.c.key == services_compatibility.c.key)
236-
& (services_meta_data.c.version == services_compatibility.c.version),
237-
)
238-
)
239-
.where(access_rights)
240-
.subquery("accessible_sq")
241-
)
242-
243-
history_subquery = (
244-
sa.select(
245-
services_meta_data.c.key,
246-
services_meta_data.c.version,
247-
services_meta_data.c.version_display,
248-
services_meta_data.c.deprecated,
249-
services_meta_data.c.created,
250-
services_compatibility.c.custom_policy, # CompatiblePolicyDict | None
251-
)
252-
.select_from(
253-
services_meta_data.join(
254-
_accessible_sq,
255-
(services_meta_data.c.key == _accessible_sq.c.key)
256-
& (services_meta_data.c.version == _accessible_sq.c.version),
257-
).outerjoin(
258-
services_compatibility,
259-
(services_meta_data.c.key == services_compatibility.c.key)
260-
& (services_meta_data.c.version == services_compatibility.c.version),
261-
)
262-
)
263-
.order_by(
264-
services_meta_data.c.key,
265-
sa.desc(_version(services_meta_data.c.version)), # latest version first
266-
)
267-
.subquery("history_sq")
268-
)
269-
270-
return (
271-
sa.select(
272-
latest_query.c.key,
273-
latest_query.c.version,
274-
# display
275-
latest_query.c.name,
276-
latest_query.c.description,
277-
latest_query.c.description_ui,
278-
latest_query.c.thumbnail,
279-
latest_query.c.icon,
280-
latest_query.c.version_display,
281-
# ownership
282-
latest_query.c.owner_email,
283-
# tags
284-
latest_query.c.classifiers,
285-
latest_query.c.quality,
286-
# lifetime
287-
latest_query.c.created,
288-
latest_query.c.modified,
289-
latest_query.c.deprecated,
290-
# releases (NOTE: at some points we should limit this list?)
291-
array_agg(
292-
func.json_build_object(
293-
"version",
294-
history_subquery.c.version,
295-
"version_display",
296-
history_subquery.c.version_display,
297-
"deprecated",
298-
history_subquery.c.deprecated,
299-
"created",
300-
history_subquery.c.created,
301-
"compatibility_policy", # NOTE: this is the `policy`
302-
history_subquery.c.custom_policy,
303-
)
304-
).label("history"),
305-
)
306-
.join(
307-
history_subquery,
308-
latest_query.c.key == history_subquery.c.key,
309-
)
310-
.group_by(
311-
history_subquery.c.key,
312-
latest_query.c.key,
313-
latest_query.c.version,
314-
latest_query.c.owner_email,
315-
latest_query.c.name,
316-
latest_query.c.description,
317-
latest_query.c.description_ui,
318-
latest_query.c.thumbnail,
319-
latest_query.c.icon,
320-
latest_query.c.version_display,
321-
latest_query.c.classifiers,
322-
latest_query.c.created,
323-
latest_query.c.modified,
324-
latest_query.c.deprecated,
325-
latest_query.c.quality,
326-
)
327-
.order_by(history_subquery.c.key)
328-
)
209+
return sa.select(
210+
latest_stmt.c.key,
211+
latest_stmt.c.version,
212+
# display
213+
latest_stmt.c.name,
214+
latest_stmt.c.description,
215+
latest_stmt.c.description_ui,
216+
latest_stmt.c.thumbnail,
217+
latest_stmt.c.icon,
218+
latest_stmt.c.version_display,
219+
# ownership
220+
latest_stmt.c.owner_email,
221+
# tags
222+
latest_stmt.c.classifiers,
223+
latest_stmt.c.quality,
224+
# lifetime
225+
latest_stmt.c.created,
226+
latest_stmt.c.modified,
227+
latest_stmt.c.deprecated,
228+
).order_by(latest_stmt.c.key)
329229

330230

331231
def can_get_service_stmt(

services/catalog/src/simcore_service_catalog/db/repositories/services.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
can_get_service_stmt,
3939
get_service_history_stmt,
4040
get_service_stmt,
41-
list_latest_services_with_history_stmt,
41+
list_latest_services_stmt,
4242
list_services_stmt,
4343
total_count_stmt,
4444
)
@@ -126,7 +126,7 @@ async def list_service_releases(
126126
search_condition &= services_meta_data.c.version.like(f"{major}.%")
127127

128128
query = (
129-
sa.select(SERVICES_META_DATA_COLS)
129+
sa.select(*SERVICES_META_DATA_COLS)
130130
.where(search_condition)
131131
.order_by(sa.desc(services_meta_data.c.version))
132132
)
@@ -386,15 +386,15 @@ async def list_latest_services(
386386
user_id=user_id,
387387
access_rights=AccessRightsClauses.can_read,
388388
)
389-
stmt_page = list_latest_services_with_history_stmt(
389+
stmt_page = list_latest_services_stmt(
390390
product_name=product_name,
391391
user_id=user_id,
392392
access_rights=AccessRightsClauses.can_read,
393393
limit=limit,
394394
offset=offset,
395395
)
396396

397-
async with self.db_engine.begin() as conn:
397+
async with self.db_engine.connect() as conn:
398398
result = await conn.execute(stmt_total)
399399
total_count = result.scalar() or 0
400400

@@ -424,7 +424,7 @@ async def list_latest_services(
424424
modified=r.modified,
425425
deprecated=r.deprecated,
426426
# releases
427-
history=r.history,
427+
history=[], # NOTE: for listing we will not add history. Only get service will produce history
428428
)
429429
for r in rows
430430
]
@@ -446,7 +446,7 @@ async def get_service_history(
446446
access_rights=AccessRightsClauses.can_read,
447447
service_key=key,
448448
)
449-
async with self.db_engine.begin() as conn:
449+
async with self.db_engine.connect() as conn:
450450
result = await conn.execute(stmt_history)
451451
row = result.one_or_none()
452452

services/catalog/src/simcore_service_catalog/services/function_services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def _as_dict(model_instance: ServiceMetaDataPublished) -> dict[str, Any]:
2020
def get_function_service(key, version) -> ServiceMetaDataPublished:
2121
try:
2222
return next(
23-
s
24-
for s in iter_service_docker_data()
25-
if s.key == key and s.version == version
23+
sc
24+
for sc in iter_service_docker_data()
25+
if sc.key == key and sc.version == version
2626
)
2727
except StopIteration as err:
2828
raise HTTPException(

services/catalog/src/simcore_service_catalog/services/manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Services Manifest API Documentation
1+
"""Services Manifest API Documentation
22
33
The `services.manifest` module provides a read-only API to access the services catalog. The term "Manifest" refers to a detailed, finalized list,
44
traditionally used to denote items that are recorded as part of an official inventory or log, emphasizing the immutable nature of the data.
@@ -60,7 +60,7 @@ async def get_services_map(
6060

6161
# NOTE: functional-services are services w/o associated image
6262
services: ServiceMetaDataPublishedDict = {
63-
(s.key, s.version): s for s in iter_service_docker_data()
63+
(sc.key, sc.version): sc for sc in iter_service_docker_data()
6464
}
6565
for service in services_in_registry:
6666
try:

0 commit comments

Comments
 (0)