Skip to content

Commit 7515271

Browse files
committed
perf(db): enable auto-vacuum and add periodic maintenance
1 parent f955ea1 commit 7515271

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • packages/opencode/src/storage

packages/opencode/src/storage/db.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export const Client = lazy(() => {
9393
db.run("PRAGMA foreign_keys = ON")
9494
db.run("PRAGMA wal_checkpoint(PASSIVE)")
9595

96+
// One-time auto-vacuum migration: switch from none (0) to incremental (2)
97+
const autoVacuum = db.$client.prepare("PRAGMA auto_vacuum").get() as { auto_vacuum: number } | undefined
98+
if (autoVacuum?.auto_vacuum === 0) {
99+
log.info("enabling incremental auto_vacuum")
100+
db.run("PRAGMA auto_vacuum = 2")
101+
db.run("VACUUM")
102+
}
103+
96104
// Apply schema migrations
97105
const entries =
98106
typeof OPENCODE_MIGRATIONS !== "undefined"
@@ -170,3 +178,11 @@ export function transaction<T>(
170178
throw err
171179
}
172180
}
181+
182+
export function checkpoint() {
183+
Client().$client.run("PRAGMA wal_checkpoint(TRUNCATE)")
184+
}
185+
186+
export function vacuum() {
187+
Client().$client.run("PRAGMA incremental_vacuum")
188+
}

0 commit comments

Comments
 (0)