| ... | @@ -61,32 +61,36 @@ const parallelRequests = new Map<string, Promise<http.IncomingMessage>>(); | ... | @@ -61,32 +61,36 @@ const parallelRequests = new Map<string, Promise<http.IncomingMessage>>(); |
| 61 | | 61 | |
| 62 | // Revive disk cache state | 62 | // Revive disk cache state |
| 63 | revive: { | 63 | revive: { |
| 64 | const state = diskCacheState | 64 | try { |
| 65 | .readIfExistsSync<Lru.Serialized<string, number>>("json"); | 65 | const state = diskCacheState |
| 66 | if (!state) break revive; | 66 | .readIfExistsSync<Lru.Serialized<string, number>>("json"); |
| 67 | const missing = new Set(diskCacheRoot.readDirSync().map((c) => c.base)); | 67 | if (!state) break revive; |
| 68 | missing.delete(diskCacheState.base); | 68 | const missing = new Set(diskCacheRoot.readDirSync().map((c) => c.base)); |
| 69 | diskCache.revive(state, { | 69 | missing.delete(diskCacheState.base); |
| 70 | map(k: string, v: number) { | 70 | diskCache.revive(state, { |
| 71 | const path = new Path(k); | 71 | map(k: string, v: number) { |
| | 72 | const path = new Path(k); |
| | 73 | try { |
| | 74 | const { size } = path.statSync(); |
| | 75 | if (size !== v) return null; |
| | 76 | if (!missing.delete(k)) return null; |
| | 77 | return [ |
| | 78 | path, |
| | 79 | { size, written: new async.Watch(size), memory: new Map() }, |
| | 80 | ]; |
| | 81 | } catch { |
| | 82 | return null; |
| | 83 | } |
| | 84 | }, |
| | 85 | }); |
| | 86 | // Delete unreferenced files |
| | 87 | for (const missingFile of missing) { |
| 72 | try { | 88 | try { |
| 73 | const { size } = path.statSync(); | 89 | diskCacheRoot.join(missingFile).deleteSync(); |
| 74 | if (size !== v) return null; | 90 | } catch {} |
| 75 | if (!missing.delete(k)) return null; | 91 | } |
| 76 | return [ | 92 | } catch (err) { |
| 77 | path, | 93 | console.warn("Failed to restore file viewer cache", err); |
| 78 | { size, written: new async.Watch(size), memory: new Map() }, | | |
| 79 | ]; | | |
| 80 | } catch { | | |
| 81 | return null; | | |
| 82 | } | | |
| 83 | }, | | |
| 84 | }); | | |
| 85 | // Delete unreferenced files | | |
| 86 | for (const missingFile of missing) { | | |
| 87 | try { | | |
| 88 | diskCacheRoot.join(missingFile).deleteSync(); | | |
| 89 | } catch {} | | |
| 90 | } | 94 | } |
| 91 | } | 95 | } |
| 92 | | 96 | |