Run WAL checkpoint on exit

This commit is contained in:
Fedor Indutny 2021-08-17 14:55:34 -07:00 committed by GitHub
parent 763c35e546
commit d222376b8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,7 @@ import {
import { ReadStatus } from '../messages/MessageReadStatus';
import { GroupV2MemberType } from '../model-types.d';
import * as Errors from '../types/errors';
import { ReactionType } from '../types/Reactions';
import { StoredJob } from '../jobs/types';
import { assert } from '../util/assert';
@ -2286,9 +2287,17 @@ async function close(): Promise<void> {
const dbRef = globalInstance;
globalInstance = undefined;
// SQLLite documentation suggests that we run `PRAGMA optimize` right before
// closing the database connection.
dbRef.pragma('optimize');
if (!isRenderer()) {
// SQLLite documentation suggests that we run `PRAGMA optimize` right
// before closing the database connection.
dbRef.pragma('optimize');
try {
dbRef.pragma('wal_checkpoint(TRUNCATE)');
} catch (error) {
console.error('Failed to truncate WAL log', Errors.toLogFormat(error));
}
}
dbRef.close();
}