Răsfoiți Sursa

fix: SQLite 写事务后 checkpoint,ops.db 自包含便于备份

liangzhao 2 săptămâni în urmă
părinte
comite
c40593a724
1 a modificat fișierele cu 3 adăugiri și 0 ștergeri
  1. 3 0
      server/stores/ops-sqlite.js

+ 3 - 0
server/stores/ops-sqlite.js

@@ -206,6 +206,8 @@ function createSqliteStore({ file }) {
     try {
       const result = await fn({ insertUpload, upsertRows, upsertShops, deleteRowsByUpload, updateReport });
       handle.exec('COMMIT');
+      // 写事务结束后做一次 checkpoint:让 data/ops.db 自包含,备份时不必关心 -wal
+      try { handle.exec('PRAGMA wal_checkpoint(TRUNCATE)'); } catch { /* 有读事务时跳过 */ }
       return result;
     } catch (e) {
       try { handle.exec('ROLLBACK'); } catch { /* 事务可能已结束 */ }
@@ -301,6 +303,7 @@ function createSqliteStore({ file }) {
 
   async function close() {
     if (db) {
+      try { db.exec('PRAGMA wal_checkpoint(TRUNCATE)'); } catch { /* ignore */ }
       try { db.close(); } catch { /* ignore */ }
       db = null;
       initPromise = null;