diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index c2d99d126..2b9b60611 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -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 { 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(); }