abinazebinoy commited on
Commit
b20b3a7
·
1 Parent(s): 9195906

fix(SyntaxError): remove duplicate stats cache block in api/main.py -- global must precede all use of variable

Browse files
Files changed (1) hide show
  1. api/main.py +4 -18
api/main.py CHANGED
@@ -119,16 +119,10 @@ def health_check():
119
  )
120
 
121
 
122
- # H-07 FIX: cache stats response to avoid full graph scan on every homepage load
123
- _stats_cache = None
124
- _stats_cached_at = 0.0
125
- _STATS_TTL = 60.0 # seconds
126
-
127
-
128
- # H-07 FIX: cache /stats for 60s -- MATCH(n) is a full graph scan
129
- _stats_cache = None
130
- _stats_cached_at = 0.0
131
- _STATS_TTL = 60.0
132
 
133
 
134
  @app.get("/stats", response_model=StatsResponse)
@@ -138,14 +132,6 @@ def get_stats():
138
  _now = _time.monotonic()
139
  if _stats_cache is not None and (_now - _stats_cached_at) < _STATS_TTL:
140
  return _stats_cache
141
- # fallthrough to compute
142
- global _stats_cache, _stats_cached_at
143
- import time as _time
144
-
145
- now = _time.monotonic()
146
- # Return cached result if fresh
147
- if _stats_cache is not None and (now - _stats_cached_at) < _STATS_TTL:
148
- return _stats_cache
149
 
150
  driver = get_driver()
151
  node_counts = {}
 
119
  )
120
 
121
 
122
+ # H-07 FIX: module-level cache vars (must be at module scope, not inside function)
123
+ _stats_cache = None
124
+ _stats_cached_at = 0.0
125
+ _STATS_TTL = 60.0
 
 
 
 
 
 
126
 
127
 
128
  @app.get("/stats", response_model=StatsResponse)
 
132
  _now = _time.monotonic()
133
  if _stats_cache is not None and (_now - _stats_cached_at) < _STATS_TTL:
134
  return _stats_cache
 
 
 
 
 
 
 
 
135
 
136
  driver = get_driver()
137
  node_counts = {}