Fix sql error when restoring from interrupted sync

This commit is contained in:
Fedor Indutny
2025-02-12 10:37:51 -08:00
committed by GitHub
parent 4c3db76bde
commit 674a0f1662
3 changed files with 21 additions and 9 deletions

View File

@@ -541,6 +541,9 @@ export const DataWriter: ServerWritableInterface = {
enableMessageInsertTriggersAndBackfill,
ensureMessageInsertTriggersAreEnabled,
disableFSync,
enableFSyncAndCheckpoint,
// Server-only
removeKnownStickers,
@@ -7490,9 +7493,6 @@ function disableMessageInsertTriggers(db: WritableDB): void {
db.exec('DROP TRIGGER IF EXISTS messages_on_insert;');
db.exec('DROP TRIGGER IF EXISTS messages_on_insert_insert_mentions;');
})();
db.pragma('checkpoint_fullfsync = false');
db.pragma('synchronous = OFF');
}
const selectMentionsFromMessages = `
@@ -7503,6 +7503,19 @@ const selectMentionsFromMessages = `
WHERE bodyRanges.value ->> 'mentionAci' IS NOT NULL
`;
function disableFSync(db: WritableDB): void {
db.pragma('checkpoint_fullfsync = false');
db.pragma('synchronous = OFF');
}
function enableFSyncAndCheckpoint(db: WritableDB): void {
db.pragma('checkpoint_fullfsync = true');
db.pragma('synchronous = FULL');
// Finally fully commit WAL into the database
db.pragma('wal_checkpoint(FULL)');
}
function enableMessageInsertTriggersAndBackfill(db: WritableDB): void {
const createTriggersQuery = `
DROP TRIGGER IF EXISTS messages_on_insert;
@@ -7532,12 +7545,6 @@ function enableMessageInsertTriggersAndBackfill(db: WritableDB): void {
value: false,
});
})();
db.pragma('checkpoint_fullfsync = true');
db.pragma('synchronous = FULL');
// Finally fully commit WAL into the database
db.pragma('wal_checkpoint(FULL)');
}
function backfillMessagesFtsTable(db: WritableDB): void {