Close database in renderer
This commit is contained in:
parent
f3ba979246
commit
ac55b8d643
1 changed files with 5 additions and 16 deletions
|
@ -32,7 +32,6 @@ import {
|
||||||
|
|
||||||
import { ReadStatus } from '../messages/MessageReadStatus';
|
import { ReadStatus } from '../messages/MessageReadStatus';
|
||||||
import { GroupV2MemberType } from '../model-types.d';
|
import { GroupV2MemberType } from '../model-types.d';
|
||||||
import * as Errors from '../types/errors';
|
|
||||||
import { ReactionType } from '../types/Reactions';
|
import { ReactionType } from '../types/Reactions';
|
||||||
import { StoredJob } from '../jobs/types';
|
import { StoredJob } from '../jobs/types';
|
||||||
import { assert } from '../util/assert';
|
import { assert } from '../util/assert';
|
||||||
|
@ -2280,26 +2279,16 @@ async function initializeRenderer({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function close(): Promise<void> {
|
async function close(): Promise<void> {
|
||||||
if (!globalInstance) {
|
for (const dbRef of [globalInstanceRenderer, globalInstance]) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dbRef = globalInstance;
|
|
||||||
globalInstance = undefined;
|
|
||||||
|
|
||||||
if (!isRenderer()) {
|
|
||||||
// SQLLite documentation suggests that we run `PRAGMA optimize` right
|
// SQLLite documentation suggests that we run `PRAGMA optimize` right
|
||||||
// before closing the database connection.
|
// before closing the database connection.
|
||||||
dbRef.pragma('optimize');
|
dbRef?.pragma('optimize');
|
||||||
|
|
||||||
try {
|
dbRef?.close();
|
||||||
dbRef.pragma('wal_checkpoint(TRUNCATE)');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to truncate WAL log', Errors.toLogFormat(error));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dbRef.close();
|
globalInstance = undefined;
|
||||||
|
globalInstanceRenderer = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeDB(): Promise<void> {
|
async function removeDB(): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue