Download packages/app/src/context/global-sync/eviction.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 964 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/context/global-sync/eviction.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/context/global-sync/eviction.ts
-
curl -L -o eviction.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/context/global-sync/eviction.ts
964 Bytes
| import type { DisposeCheck, EvictPlan } from "./types" | |
| export function pickDirectoriesToEvict(input: EvictPlan) { | |
| const overflow = Math.max(0, input.stores.length - input.max) | |
| let pendingOverflow = overflow | |
| const sorted = input.stores | |
| .filter((dir) => !input.pins.has(dir)) | |
| .slice() | |
| .sort((a, b) => (input.state.get(a)?.lastAccessAt ?? 0) - (input.state.get(b)?.lastAccessAt ?? 0)) | |
| const output: string[] = [] | |
| for (const dir of sorted) { | |
| const last = input.state.get(dir)?.lastAccessAt ?? 0 | |
| const idle = input.now - last >= input.ttl | |
| if (!idle && pendingOverflow <= 0) continue | |
| output.push(dir) | |
| if (pendingOverflow > 0) pendingOverflow -= 1 | |
| } | |
| return output | |
| } | |
| export function canDisposeDirectory(input: DisposeCheck) { | |
| if (!input.directory) return false | |
| if (!input.hasStore) return false | |
| if (input.pinned) return false | |
| if (input.booting) return false | |
| if (input.loadingSessions) return false | |
| return true | |
| } | |