Commit 1821766
perf(cache): add P2 medium-priority performance and robustness improvements
Address five P2 (medium priority) issues from code review:
**P2-1: Stale Lock Detection**
- Add PID and timestamp to lock files
- Detect and remove stale locks (dead process or >60s old)
- Prevents permanent lockouts from crashed processes
- Files: src/utils/diskCache.ts
**P2-2: Configurable Cache Directory**
- Support PDF_READER_CACHE_DIR environment variable
- Uses MD5 hash suffix to avoid filename collisions
- Falls back to PDF directory (current behavior) if not set
- Useful for read-only filesystems and centralized caching
- Files: src/utils/diskCache.ts
**P2-3: Decision Cache Race Fix**
- Remove problematic delete-before-set pattern
- Rely on Map.set() overwrite semantics (preserves insertion order)
- Use while loop for consistent eviction behavior
- Files: src/handlers/pdfOcr.ts
**P2-4: Batched Image Extraction**
- Process images in batches of 6 to prevent memory pressure
- Replaces unbounded Promise.all with batched processing
- Maintains parallelism within batches for performance
- Files: src/pdf/extractor.ts
**P2-5: Smart OCR Optimization**
- Skip text extraction when cached decision says OCR needed
- Avoids redundant work on subsequent smart_ocr calls
- Improves performance for scanned documents
- Files: src/handlers/pdfOcr.ts
All improvements maintain backward compatibility. No breaking changes.
Tests: 144 passing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 90b55ca commit 1821766
3 files changed
+98
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
234 | | - | |
235 | | - | |
236 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
237 | 249 | | |
238 | | - | |
239 | | - | |
240 | 250 | | |
241 | 251 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | 252 | | |
247 | 253 | | |
248 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
329 | 327 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
337 | 334 | | |
338 | | - | |
339 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
340 | 346 | | |
341 | 347 | | |
342 | 348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| 29 | + | |
21 | 30 | | |
22 | 31 | | |
23 | | - | |
| 32 | + | |
24 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
25 | 43 | | |
26 | 44 | | |
27 | 45 | | |
| |||
64 | 82 | | |
65 | 83 | | |
66 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
67 | 116 | | |
68 | 117 | | |
69 | 118 | | |
70 | 119 | | |
71 | 120 | | |
72 | 121 | | |
73 | 122 | | |
| 123 | + | |
| 124 | + | |
74 | 125 | | |
75 | 126 | | |
76 | 127 | | |
77 | 128 | | |
78 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
79 | 137 | | |
80 | 138 | | |
81 | 139 | | |
| |||
0 commit comments