Commit 1bad1a3
* feat: Cache Retraction Watch backend results to prevent redundant API calls
Refactor RetractionWatchBackend to use HybridBackend pattern for proper
result caching. This eliminates redundant OpenAlex API calls when
retraction assessment results are already cached.
Changes:
- Change inheritance from CachedBackend to HybridBackend
- Rename query() to _query_api() for HybridBackend compatibility
- Add configurable cache_ttl_hours parameter (default: 24 hours)
- Add helper methods _search_exact_match() and _calculate_confidence()
- Update backend factory registration to support configurable TTL
Tests:
- Add comprehensive test suite with 9 test cases
- Verify cache hit behavior (no API calls)
- Verify cache miss triggers API queries and caches result
- Verify cached queries complete in <50ms
- Verify configurable cache TTL
- Verify NOT_FOUND results are also cached
Benefits:
- Cached queries complete in <50ms (vs 500-1500ms previously)
- Zero OpenAlex API calls when cached result exists
- cached=True flag set correctly for cached queries
- Consistent with other backends (DOAJ, Crossref, OpenAlex)
Fixes #53
[AI-assisted]
* 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]
---------
Co-authored-by: florath-ai-assistant[bot] <Andreas.Florath@telekom.de>
1 parent 7276e5e commit 1bad1a3
File tree
3 files changed
+380
-13
lines changed- src/aletheia_probe/backends
- tests/unit/backends
3 files changed
+380
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
| 230 | + | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
| 234 | + | |
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | | - | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
| |||
228 | 236 | | |
229 | 237 | | |
230 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
231 | 285 | | |
232 | 286 | | |
233 | 287 | | |
| |||
258 | 312 | | |
259 | 313 | | |
260 | 314 | | |
261 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
262 | 318 | | |
0 commit comments