Skip to content

Commit d0cb6ba

Browse files
committed
Added caching of the stats
1 parent 140e3b9 commit d0cb6ba

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

bedhost/dependencies.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from cachetools import cached, TTLCache
2+
from .main import bbagent
3+
from bbconf.models.base_models import FileStats
4+
5+
6+
@cached(TTLCache(maxsize=100, ttl=5 * 60))
7+
def fetch_detailed_stats(concise: bool = False) -> FileStats:
8+
return bbagent.get_detailed_stats(concise=concise)

bedhost/routers/base_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ServiceInfoResponse,
2121
Type,
2222
)
23+
from ..dependencies import fetch_detailed_stats
2324
from ..helpers import get_openapi_version, count_requests
2425
from ..main import app, bbagent, usage_data
2526

@@ -52,7 +53,7 @@ async def get_detailed_stats(
5253
"""
5354
Returns detailed statistics
5455
"""
55-
return bbagent.get_detailed_stats(concise=concise)
56+
return fetch_detailed_stats(concise=concise)
5657

5758

5859
@router.get(

requirements/requirements-all.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ pephubclient>=0.4.1
1111
psycopg[binary,pool]
1212
python-multipart>=0.0.9
1313
APScheduler>=3.11.0
14+
cachetools>=4.2.4
15+

0 commit comments

Comments
 (0)