Storage: configurable data dir for the external drive + daily DB prune
HOST_DATA_DIR in .env can now point /data at a host path (the 1TB external drive) instead of the named volume, so odds history, caches and snapshots stop eating the 128GB root disk. A daily prune drops cache entries stale for over a week and ingest-log rows older than 14 days — faster polling no longer means unbounded DB growth. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -135,6 +135,19 @@ export function cacheSet(key: string, value: string, ttl: number): void {
|
||||
.run(key, value, Date.now(), ttl);
|
||||
}
|
||||
|
||||
/** Bound DB growth: drop cache entries stale for >7 days (the breaker only ever
|
||||
* serves recent staleness) and ingest-log rows older than 14 days. Returns the
|
||||
* number of rows removed. Runs daily from the scheduler. */
|
||||
export function prune(now = Date.now()): number {
|
||||
const cache = db()
|
||||
.prepare('DELETE FROM kv_cache WHERE ? - fetched_at > ttl + 7 * 86400000')
|
||||
.run(now);
|
||||
const log = db()
|
||||
.prepare('DELETE FROM ingest_log WHERE at < ?')
|
||||
.run(now - 14 * 86400000);
|
||||
return Number(cache.changes) + Number(log.changes);
|
||||
}
|
||||
|
||||
// ---- source health / circuit breaker ----
|
||||
export interface SourceHealthRow {
|
||||
source: string;
|
||||
|
||||
Reference in New Issue
Block a user