Close database in renderer

This commit is contained in:
Fedor Indutny 2021-08-18 09:52:48 -07:00 committed by GitHub
parent f3ba979246
commit ac55b8d643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 16 deletions

View File

@ -32,7 +32,6 @@ 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';
@ -2280,26 +2279,16 @@ async function initializeRenderer({
}
async function close(): Promise<void> {
if (!globalInstance) {
return;
}
const dbRef = globalInstance;
globalInstance = undefined;
if (!isRenderer()) {
for (const dbRef of [globalInstanceRenderer, globalInstance]) {
// SQLLite documentation suggests that we run `PRAGMA optimize` right
// before closing the database connection.
dbRef.pragma('optimize');
dbRef?.pragma('optimize');
try {
dbRef.pragma('wal_checkpoint(TRUNCATE)');
} catch (error) {
console.error('Failed to truncate WAL log', Errors.toLogFormat(error));
}
dbRef?.close();
}
dbRef.close();
globalInstance = undefined;
globalInstanceRenderer = undefined;
}
async function removeDB(): Promise<void> {