Skip to content

Commit b06263f

Browse files
committed
fix: Update response_time for cached results in HybridBackend
The HybridBackend was returning the original response_time from when the result was first cached, causing all cached queries to show the same response time (e.g., 519.24ms) regardless of actual cache lookup speed. This fix measures the actual cache lookup time and updates response_time when returning cached results, showing the true performance (~1-2ms). Before: - Cached query: 519.24ms (always the same, from original query) After: - Cached query: 0.7-2ms (varies, actual cache lookup time) This affects all backends using HybridBackend pattern: - retraction_watch - doaj - crossref_analyzer - openalex_analyzer [AI-assisted]
1 parent 67ee196 commit b06263f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/aletheia_probe/backends/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,20 @@ def __init__(self, cache_ttl_hours: int = 24):
218218

219219
async def query(self, query_input: QueryInput) -> BackendResult:
220220
"""Check cache first, then query live API if needed."""
221+
start_time = time.time()
222+
221223
# Generate cache key for this query
222224
cache_key = self._generate_cache_key(query_input)
223225

224226
# Try cache first
225227
cached_result = get_cache_manager().get_cached_assessment(cache_key)
226228
if cached_result:
227229
# Update the cached result to indicate it came from cache
230+
cache_lookup_time = time.time() - start_time
228231
for backend_result in cached_result.backend_results:
229232
if backend_result.backend_name == self.get_name():
230233
backend_result.cached = True
234+
backend_result.response_time = cache_lookup_time
231235
backend_result.data = {**backend_result.data, "from_cache": True}
232236
return backend_result
233237

0 commit comments

Comments
 (0)