Skip to content

Commit 62d8244

Browse files
committed
only use solver_service interface when listing all solver releases
1 parent 3c52ce2 commit 62d8244

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed

services/api-server/src/simcore_service_api_server/_service_solvers.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
from common_library.pagination_tools import iter_pagination_params
44
from fastapi import Depends
5+
from models_library.api_schemas_catalog.services import ServiceListFilters
56
from models_library.basic_types import VersionStr
67
from models_library.products import ProductName
7-
from models_library.rest_pagination import MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE
8+
from models_library.rest_pagination import (
9+
MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
10+
PageMetaInfoLimitOffset,
11+
)
812
from models_library.services_enums import ServiceType
913
from models_library.services_history import ServiceRelease
1014
from models_library.users import UserID
1115
from packaging.version import Version
16+
from pydantic import NonNegativeInt, PositiveInt
1217

1318
from .models.schemas.solvers import Solver, SolverKeyId
1419
from .services_rpc.catalog import CatalogService
@@ -74,27 +79,25 @@ async def get_latest_release(
7479
async def solver_release_history(
7580
self,
7681
*,
77-
user_id: int,
82+
user_id: UserID,
7883
solver_key: SolverKeyId,
79-
product_name: str,
80-
) -> list[Solver]:
84+
product_name: ProductName,
85+
offset: NonNegativeInt,
86+
limit: PositiveInt,
87+
) -> tuple[list[Solver], PageMetaInfoLimitOffset]:
8188

82-
service_releases: list[ServiceRelease] = []
83-
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
84-
releases, page_meta = await self._catalog_service.list_release_history(
85-
user_id=user_id,
86-
service_key=solver_key,
87-
product_name=product_name,
88-
offset=page_params.offset,
89-
limit=page_params.limit,
90-
)
91-
page_params.total_number_of_items = page_meta.total
92-
service_releases.extend(releases)
89+
releases, page_meta = await self._catalog_service.list_release_history(
90+
user_id=user_id,
91+
service_key=solver_key,
92+
product_name=product_name,
93+
offset=offset,
94+
limit=limit,
95+
)
9396

9497
service_instance = await self._catalog_service.get(
9598
user_id=user_id,
9699
name=solver_key,
97-
version=service_releases[-1].version,
100+
version=releases[-1].version,
98101
product_name=product_name,
99102
)
100103

@@ -106,5 +109,25 @@ async def solver_release_history(
106109
name=service_instance.name,
107110
service=service,
108111
)
109-
for service in service_releases
110-
]
112+
for service in releases
113+
], page_meta
114+
115+
async def latest_solvers(
116+
self,
117+
*,
118+
user_id: UserID,
119+
product_name: ProductName,
120+
offset: NonNegativeInt,
121+
limit: PositiveInt,
122+
) -> tuple[list[Solver], PageMetaInfoLimitOffset]:
123+
"""Lists the latest solvers with pagination."""
124+
services, page_meta = await self._catalog_service.list_latest_releases(
125+
user_id=user_id,
126+
product_name=product_name,
127+
offset=offset,
128+
limit=limit,
129+
filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL),
130+
)
131+
132+
solvers = [Solver.create_from_service(service) for service in services]
133+
return solvers, page_meta

services/api-server/src/simcore_service_api_server/api/routes/solvers.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,46 +129,34 @@ async def get_solvers_page(
129129
)
130130
async def list_solvers_releases(
131131
user_id: Annotated[int, Depends(get_current_user_id)],
132-
catalog_service: Annotated[CatalogService, Depends()],
132+
solver_service: Annotated[SolverService, Depends(SolverService)],
133133
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
134134
product_name: Annotated[str, Depends(get_product_name)],
135135
):
136136

137-
latest_releases = []
137+
latest_solvers: list[Solver] = []
138138
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
139-
services, page_meta = await catalog_service.list_latest_releases(
139+
solvers, page_meta = await solver_service.latest_solvers(
140140
user_id=user_id,
141141
product_name=product_name,
142142
offset=page_params.offset,
143143
limit=page_params.limit,
144-
filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL),
145144
)
146145
page_params.total_number_of_items = page_meta.total
147-
latest_releases.extend(services)
146+
latest_solvers.extend(solvers)
148147

149148
all_solvers = []
150-
for service_release in latest_releases:
149+
for solver in latest_solvers:
151150
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
152-
services, page_meta = await catalog_service.list_release_history(
151+
solvers, page_meta = await solver_service.solver_release_history(
153152
product_name=product_name,
154153
user_id=user_id,
155-
service_key=service_release.key,
154+
solver_key=solver.id,
156155
offset=page_params.offset,
157156
limit=page_params.limit,
158157
)
159158
page_params.total_number_of_items = page_meta.total
160-
all_solvers.extend(
161-
[
162-
Solver.create_from_service_release(
163-
service_key=service_release.key,
164-
description=service_release.description,
165-
contact=service_release.contact,
166-
name=service_release.name,
167-
service=service,
168-
)
169-
for service in services
170-
]
171-
)
159+
all_solvers.extend(solvers)
172160

173161
for solver in all_solvers:
174162
solver.url = url_for(

0 commit comments

Comments
 (0)