Skip to content

Commit 2a3913b

Browse files
authored
🐛Separate caching director call from user dependent service listing (ITISFoundation#3020)
1 parent eec1f9e commit 2a3913b

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

packages/models-library/src/models_library/services_access.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
class ServiceGroupAccessRights(BaseModel):
1313
execute_access: bool = Field(
14-
False,
14+
default=False,
1515
description="defines whether the group can execute the service",
1616
)
1717
write_access: bool = Field(
18-
False, description="defines whether the group can modify the service"
18+
default=False, description="defines whether the group can modify the service"
1919
)
2020

2121

services/catalog/src/simcore_service_catalog/api/routes/services.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import asyncio
44
import logging
55
import urllib.parse
6-
from collections import deque
7-
from typing import Any, Deque, Dict, Final, List, Optional, Set, Tuple, cast
6+
from typing import Any, Dict, Final, List, Optional, Set, Tuple, cast
87

98
from aiocache import cached
109
from fastapi import APIRouter, Depends, Header, HTTPException, status
@@ -143,19 +142,11 @@ async def list_services(
143142

144143
# caching this steps brings down the time to generate it at the expense of being sometimes a bit out of date
145144
@cached(ttl=DIRECTOR_CACHING_TTL)
146-
async def cached_registry_services() -> Deque[Tuple[str, str, Dict[str, Any]]]:
147-
services_in_registry = await director_client.get("/services")
148-
filtered_services = deque(
149-
(s["key"], s["version"], s)
150-
for s in (
151-
request.app.state.frontend_services_catalog + services_in_registry
152-
)
153-
if (s.get("key"), s.get("version")) in services_in_db
154-
)
155-
return filtered_services
145+
async def cached_registry_services() -> dict[str, Any]:
146+
return cast(dict[str, Any], await director_client.get("/services"))
156147

157148
(
158-
registry_filtered_services,
149+
services_in_registry,
159150
services_access_rights,
160151
services_owner_emails,
161152
) = await asyncio.gather(
@@ -180,12 +171,17 @@ async def cached_registry_services() -> Deque[Tuple[str, str, Dict[str, Any]]]:
180171
asyncio.get_event_loop().run_in_executor(
181172
None,
182173
_prepare_service_details,
183-
details,
184-
services_in_db[key, version],
185-
services_access_rights[key, version],
186-
services_owner_emails.get(services_in_db[key, version].owner),
174+
s,
175+
services_in_db[s["key"], s["version"]],
176+
services_access_rights[s["key"], s["version"]],
177+
services_owner_emails.get(
178+
services_in_db[s["key"], s["version"]].owner or 0
179+
),
187180
)
188-
for key, version, details in registry_filtered_services
181+
for s in (
182+
request.app.state.frontend_services_catalog + services_in_registry
183+
)
184+
if (s.get("key"), s.get("version")) in services_in_db
189185
]
190186
)
191187
return [s for s in services_details if s is not None]
@@ -315,8 +311,11 @@ async def get_service(
315311
)
316312
_service_data = frontend_service
317313
else:
318-
services_in_registry = await director_client.get(
319-
f"/services/{urllib.parse.quote_plus(service_key)}/{service_version}"
314+
services_in_registry = cast(
315+
list[Any],
316+
await director_client.get(
317+
f"/services/{urllib.parse.quote_plus(service_key)}/{service_version}"
318+
),
320319
)
321320
_service_data = services_in_registry[0]
322321

services/catalog/src/simcore_service_catalog/utils/requests_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def _cancel_task_if_client_disconnected(
2424
await asyncio.sleep(interval)
2525

2626

27-
def cancellable_request(handler: Callable[..., Coroutine[Any, Any, Response]]):
27+
def cancellable_request(handler: Callable[..., Coroutine[Any, Any, Any]]):
2828
"""this decorator periodically checks if the client disconnected and then will cancel the request and return a 499 code (a la nginx)."""
2929

3030
@wraps(handler)

0 commit comments

Comments
 (0)