From aa2c0e33dd605fcae39aefdeeb8adfe5a69b4daa Mon Sep 17 00:00:00 2001 From: Marcus <1922576605@qq.com> Date: Tue, 6 Oct 2026 21:41:18 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20SQLite=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20busy=5Ftimeout=20=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/db/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/db/index.ts b/src/server/db/index.ts index 1b526ee..a0399f8 100644 --- a/src/server/db/index.ts +++ b/src/server/db/index.ts @@ -8,8 +8,12 @@ const createDb = () => { const file = getDbFileName(); mkdirSync(dirname(file), { recursive: true }); const db = drizzle({ connection: { path: file } }); - // node:sqlite 是同步驱动,写入会阻塞事件循环;WAL + NORMAL 下提交不再逐次刷盘 - db.$client.exec("PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;"); + // node:sqlite 是同步驱动,写入会阻塞事件循环;WAL + NORMAL 下提交不再逐次刷盘。 + // busy_timeout 必须排在最前:默认遇到锁立刻报 database is locked,而 next build 的多个 + // worker 会同时导入本模块、同时切换新库文件的 WAL 模式,后到的要等前一个切完 + db.$client.exec( + "PRAGMA busy_timeout = 5000; PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;" + ); return db; };