Skip to content

Commit 412d4d1

Browse files
refactor: simplify function calls and improve readability
- Consolidate parameters in get_or_set_cache calls in libraries.py, specs.py, and stats.py - Clean up function definition in cache.py for _background_refresh
1 parent 970e848 commit 412d4d1

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

api/cache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ def _schedule_refresh(key: str, factory: Callable[[], Awaitable[Any]]) -> None:
245245
asyncio.create_task(_background_refresh(key, factory, lock))
246246

247247

248-
async def _background_refresh(
249-
key: str, factory: Callable[[], Awaitable[Any]], lock: asyncio.Lock
250-
) -> None:
248+
async def _background_refresh(key: str, factory: Callable[[], Awaitable[Any]], lock: asyncio.Lock) -> None:
251249
"""Run factory in background and update cache. Errors are logged, not raised."""
252250
async with lock:
253251
try:

api/routers/libraries.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ async def _fetch() -> dict:
6262
}
6363

6464
return await get_or_set_cache(
65-
cache_key("libraries"),
66-
_fetch,
67-
refresh_after=settings.cache_refresh_after,
68-
refresh_factory=_refresh_libraries,
65+
cache_key("libraries"), _fetch, refresh_after=settings.cache_refresh_after, refresh_factory=_refresh_libraries
6966
)
7067

7168

api/routers/specs.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ async def _refresh_specs_list() -> list[SpecListItem]:
2323
specs = await repo.get_all()
2424
return [
2525
SpecListItem(
26-
id=spec.id, title=spec.title, description=spec.description, tags=spec.tags, library_count=len(spec.impls)
26+
id=spec.id,
27+
title=spec.title,
28+
description=spec.description,
29+
tags=spec.tags,
30+
library_count=len(spec.impls),
2731
)
2832
for spec in specs
2933
if spec.impls
@@ -43,17 +47,18 @@ async def _fetch() -> list[SpecListItem]:
4347
specs = await repo.get_all()
4448
return [
4549
SpecListItem(
46-
id=spec.id, title=spec.title, description=spec.description, tags=spec.tags, library_count=len(spec.impls)
50+
id=spec.id,
51+
title=spec.title,
52+
description=spec.description,
53+
tags=spec.tags,
54+
library_count=len(spec.impls),
4755
)
4856
for spec in specs
4957
if spec.impls
5058
]
5159

5260
return await get_or_set_cache(
53-
cache_key("specs_list"),
54-
_fetch,
55-
refresh_after=settings.cache_refresh_after,
56-
refresh_factory=_refresh_specs_list,
61+
cache_key("specs_list"), _fetch, refresh_after=settings.cache_refresh_after, refresh_factory=_refresh_specs_list
5762
)
5863

5964

api/routers/stats.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,5 @@ async def _fetch() -> StatsResponse:
7272
return StatsResponse(specs=len(specs_with_impls), plots=total_impls, libraries=len(libraries))
7373

7474
return await get_or_set_cache(
75-
cache_key("stats"),
76-
_fetch,
77-
refresh_after=settings.cache_refresh_after,
78-
refresh_factory=_refresh_stats,
75+
cache_key("stats"), _fetch, refresh_after=settings.cache_refresh_after, refresh_factory=_refresh_stats
7976
)

0 commit comments

Comments
 (0)