fixed reasoning
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -8,9 +9,28 @@ from app.projects.service import ProjectService
|
||||
|
||||
MAX_PROJECTS_IN_CONTEXT = 20
|
||||
MAX_OPEN_PER_PROJECT = 8
|
||||
PROJECTS_CACHE_SEC = 120
|
||||
|
||||
_cache: dict[str, Any] = {"data": None, "expires_at": 0.0}
|
||||
|
||||
|
||||
def get_projects_snapshot(db: Session) -> dict[str, Any]:
|
||||
def invalidate_projects_snapshot_cache() -> None:
|
||||
_cache["data"] = None
|
||||
_cache["expires_at"] = 0.0
|
||||
|
||||
|
||||
def get_projects_snapshot(db: Session, *, force: bool = False) -> dict[str, Any]:
|
||||
now = time.time()
|
||||
if not force and _cache["data"] is not None and now < _cache["expires_at"]:
|
||||
return _cache["data"]
|
||||
|
||||
snapshot = _fetch_projects_snapshot(db)
|
||||
_cache["data"] = snapshot
|
||||
_cache["expires_at"] = now + PROJECTS_CACHE_SEC
|
||||
return snapshot
|
||||
|
||||
|
||||
def _fetch_projects_snapshot(db: Session) -> dict[str, Any]:
|
||||
settings = get_settings()
|
||||
service = ProjectService(db)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user