fixed reasoning

This commit is contained in:
2026-06-10 14:56:18 +03:00
parent 89158930ee
commit e9762d7921
7 changed files with 143 additions and 23 deletions
+21 -1
View File
@@ -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)