Fix sql error when restoring from interrupted sync
This commit is contained in:
parent
3dfc61cae3
commit
5855b259f8
3 changed files with 21 additions and 9 deletions
|
@ -348,6 +348,7 @@ export class BackupsService {
|
|||
const importStart = Date.now();
|
||||
|
||||
await DataWriter.disableMessageInsertTriggers();
|
||||
await DataWriter.disableFSync();
|
||||
|
||||
try {
|
||||
window.ConversationController.setReadOnly(true);
|
||||
|
@ -445,6 +446,7 @@ export class BackupsService {
|
|||
window.ConversationController.setReadOnly(false);
|
||||
this.#isRunning = false;
|
||||
await DataWriter.enableMessageInsertTriggersAndBackfill();
|
||||
await DataWriter.enableFSyncAndCheckpoint();
|
||||
|
||||
window.IPC.stopTrackingQueryStats({ epochName: 'Backup Import' });
|
||||
if (window.SignalCI) {
|
||||
|
|
|
@ -1011,6 +1011,9 @@ type WritableInterface = {
|
|||
enableMessageInsertTriggersAndBackfill(): void;
|
||||
ensureMessageInsertTriggersAreEnabled(): void;
|
||||
|
||||
disableFSync(): void;
|
||||
enableFSyncAndCheckpoint(): void;
|
||||
|
||||
processGroupCallRingCancellation(ringId: bigint): void;
|
||||
cleanExpiredGroupCallRingCancellations(): void;
|
||||
};
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue