|
3 | 3 | from operator import attrgetter |
4 | 4 | from typing import Annotated, Any |
5 | 5 |
|
| 6 | +from common_library.pagination_tools import iter_pagination_params |
6 | 7 | from fastapi import APIRouter, Depends, HTTPException, status |
7 | | -from grpc import services |
8 | 8 | from httpx import HTTPStatusError |
9 | 9 | from models_library.api_schemas_catalog.services import ServiceListFilters |
| 10 | +from models_library.rest_pagination import MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE |
10 | 11 | from models_library.services_enums import ServiceType |
11 | 12 | from pydantic import ValidationError |
12 | 13 | from simcore_service_api_server.services_rpc.catalog import CatalogService |
|
30 | 31 | create_route_description, |
31 | 32 | ) |
32 | 33 |
|
| 34 | +DEFAULT_PAGINATION_LIMIT = MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE - 1 |
| 35 | + |
| 36 | + |
33 | 37 | _logger = logging.getLogger(__name__) |
34 | 38 |
|
35 | 39 | _SOLVER_STATUS_CODES: dict[int | str, dict[str, Any]] = { |
@@ -77,7 +81,7 @@ async def list_solvers( |
77 | 81 | ): |
78 | 82 | """Lists all available solvers (latest version)""" |
79 | 83 |
|
80 | | - services, page_info = await catalog_service.list_latest_releases( |
| 84 | + services, _ = await catalog_service.list_latest_releases( |
81 | 85 | user_id=user_id, |
82 | 86 | product_name=product_name, |
83 | 87 | filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL), |
@@ -110,26 +114,52 @@ async def get_solvers_page( |
110 | 114 | response_model=list[Solver], |
111 | 115 | summary="Lists All Releases", |
112 | 116 | responses=_SOLVER_STATUS_CODES, |
| 117 | + description=create_route_description( |
| 118 | + base="Lists all released solvers (not just latest version)", |
| 119 | + deprecated=True, |
| 120 | + alternative="GET /v0/solvers/releases/page", |
| 121 | + changelog=[ |
| 122 | + FMSG_CHANGELOG_NEW_IN_VERSION.format("0.5.0", ""), |
| 123 | + FMSG_CHANGELOG_REMOVED_IN_VERSION_FORMAT.format( |
| 124 | + "0.7", |
| 125 | + "This endpoint is deprecated and will be removed in a future version", |
| 126 | + ), |
| 127 | + ], |
| 128 | + ), |
113 | 129 | ) |
114 | 130 | async def list_solvers_releases( |
115 | 131 | user_id: Annotated[int, Depends(get_current_user_id)], |
116 | | - catalog_client: Annotated[CatalogApi, Depends(get_api_client(CatalogApi))], |
| 132 | + catalog_service: Annotated[CatalogService, Depends()], |
117 | 133 | url_for: Annotated[Callable, Depends(get_reverse_url_mapper)], |
118 | 134 | product_name: Annotated[str, Depends(get_product_name)], |
119 | 135 | ): |
120 | | - """Lists all released solvers i.e. all released versions |
121 | 136 |
|
122 | | - SEE get_solvers_releases_page for a paginated version of this function |
123 | | - """ |
124 | | - assert await catalog_client.is_responsive() # nosec |
125 | | - |
126 | | - services = await catalog_client.list_services( |
127 | | - user_id=user_id, |
128 | | - product_name=product_name, |
129 | | - predicate=None, |
130 | | - type_filter="COMPUTATIONAL", |
131 | | - ) |
132 | | - solvers = [service.to_solver() for service in services] |
| 137 | + latest_releases = [] |
| 138 | + for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT): |
| 139 | + services, page_meta = await catalog_service.list_latest_releases( |
| 140 | + user_id=user_id, |
| 141 | + product_name=product_name, |
| 142 | + offset=page_params.offset, |
| 143 | + limit=page_params.limit, |
| 144 | + filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL), |
| 145 | + ) |
| 146 | + page_params.total_number_of_items = page_meta.total |
| 147 | + latest_releases.extend(services) |
| 148 | + |
| 149 | + all_releases = [] |
| 150 | + for service in latest_releases: |
| 151 | + for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT): |
| 152 | + services, page_meta = await catalog_service.list_release_history( |
| 153 | + product_name=product_name, |
| 154 | + user_id=user_id, |
| 155 | + service_key=service.id, |
| 156 | + offset=page_params.offset, |
| 157 | + limit=page_params.limit, |
| 158 | + ) |
| 159 | + page_params.total_number_of_items = page_meta.total |
| 160 | + all_releases.extend(services) |
| 161 | + |
| 162 | + solvers = [Solver.create_from_service(service) for service in all_releases] |
133 | 163 |
|
134 | 164 | for solver in solvers: |
135 | 165 | solver.url = url_for( |
|
0 commit comments