Spaces:
Build error
Build error
Merge pull request #104 from abinaze/fix/r5-wire-cache-ttl
Browse filesWire get_cache_ttl() into _STATS_TTL and _VERIFY_TTL (R-5, partial)
- api/dependencies.py +9 -1
- api/main.py +11 -1
api/dependencies.py
CHANGED
|
@@ -17,12 +17,20 @@ from dotenv import load_dotenv
|
|
| 17 |
from loguru import logger
|
| 18 |
from neo4j import GraphDatabase
|
| 19 |
from neo4j.exceptions import ServiceUnavailable, AuthError
|
|
|
|
| 20 |
|
| 21 |
load_dotenv()
|
| 22 |
|
| 23 |
_driver = None
|
| 24 |
_last_verified_at = 0.0
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
_driver_lock = threading.Lock()
|
| 27 |
|
| 28 |
|
|
|
|
| 17 |
from loguru import logger
|
| 18 |
from neo4j import GraphDatabase
|
| 19 |
from neo4j.exceptions import ServiceUnavailable, AuthError
|
| 20 |
+
from config.model_selector import get_cache_ttl
|
| 21 |
|
| 22 |
load_dotenv()
|
| 23 |
|
| 24 |
_driver = None
|
| 25 |
_last_verified_at = 0.0
|
| 26 |
+
# R-5 fix: was a hardcoded 30.0. This TTL exists specifically to prevent
|
| 27 |
+
# the connection-storm scenario the module docstring above describes
|
| 28 |
+
# (many concurrent requests all re-verifying at once) -- a concern that
|
| 29 |
+
# scales with concurrent traffic, which is exactly what PROFILE's tiers
|
| 30 |
+
# already track (a "low" desktop install is single-user; "high" is a
|
| 31 |
+
# multi-user server). Same reasoning as _STATS_TTL in api/main.py: pure
|
| 32 |
+
# freshness/overhead trade-off, no analytical-completeness question.
|
| 33 |
+
_VERIFY_TTL = float(get_cache_ttl()) # seconds between connectivity re-checks
|
| 34 |
_driver_lock = threading.Lock()
|
| 35 |
|
| 36 |
|
api/main.py
CHANGED
|
@@ -16,6 +16,7 @@ from api.models import HealthResponse, StatsResponse
|
|
| 16 |
from processing.alias_graph import AliasGraph # Phase 32
|
| 17 |
from processing.entity_resolver_v2 import EntityResolverV2 # Phase 32
|
| 18 |
from config.runtime_profile import PROFILE as _RUNTIME_PROFILE
|
|
|
|
| 19 |
import config.settings # noqa: F401 -- Phase D1: importing this loads any
|
| 20 |
# local desktop config file into os.environ as a
|
| 21 |
# side effect (mirrors load_dotenv() above). Must
|
|
@@ -149,7 +150,16 @@ def health_check():
|
|
| 149 |
# H-07 FIX: module-level cache vars (must be at module scope, not inside function)
|
| 150 |
_stats_cache = None
|
| 151 |
_stats_cached_at = 0.0
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
import threading as _threading # B-01 FIX: was missing entirely
|
| 154 |
_stats_lock = _threading.Lock() # B-01 FIX: NameError on every GET /stats
|
| 155 |
|
|
|
|
| 16 |
from processing.alias_graph import AliasGraph # Phase 32
|
| 17 |
from processing.entity_resolver_v2 import EntityResolverV2 # Phase 32
|
| 18 |
from config.runtime_profile import PROFILE as _RUNTIME_PROFILE
|
| 19 |
+
from config.model_selector import get_cache_ttl
|
| 20 |
import config.settings # noqa: F401 -- Phase D1: importing this loads any
|
| 21 |
# local desktop config file into os.environ as a
|
| 22 |
# side effect (mirrors load_dotenv() above). Must
|
|
|
|
| 150 |
# H-07 FIX: module-level cache vars (must be at module scope, not inside function)
|
| 151 |
_stats_cache = None
|
| 152 |
_stats_cached_at = 0.0
|
| 153 |
+
# R-5 fix: was a hardcoded 60.0 (which happened to equal PROFILE["high"]'s
|
| 154 |
+
# own cache_ttl_seconds, coincidentally -- this constant predates the
|
| 155 |
+
# tiered PROFILE system entirely). Pure cache-freshness knob: changes how
|
| 156 |
+
# OFTEN /stats recomputes, never WHAT it computes -- unlike graph_depth/
|
| 157 |
+
# investigation_layers, there is no analytical-completeness trade-off
|
| 158 |
+
# here, so this one genuinely is the mechanical swap R-2/R-3/R-4 already
|
| 159 |
+
# were, not a design question. A low-resource desktop install now caches
|
| 160 |
+
# longer (300s) to avoid frequent full-graph scans; a high-tier server
|
| 161 |
+
# keeps the original 60s for fresher numbers.
|
| 162 |
+
_STATS_TTL = float(get_cache_ttl())
|
| 163 |
import threading as _threading # B-01 FIX: was missing entirely
|
| 164 |
_stats_lock = _threading.Lock() # B-01 FIX: NameError on every GET /stats
|
| 165 |
|