From ac55b8d6437702b5133155234194d6ac4dc28bce Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 18 Aug 2021 09:52:48 -0700 Subject: [PATCH] Close database in renderer --- ts/sql/Server.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index 2b9b60611694..10ab5b7e18bf 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -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 { - 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 {