From 28832e77f3c5600ed848d3a4fd47acf2e5992a09 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 24 Aug 2023 12:58:44 -0600 Subject: [PATCH] Add scheduledEventOptimizeDatabases() --- core/database.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/database.js b/core/database.js index 00777315..70efd9e2 100644 --- a/core/database.js +++ b/core/database.js @@ -22,6 +22,7 @@ exports.loadDatabaseForMod = loadDatabaseForMod; exports.getISOTimestampString = getISOTimestampString; exports.sanitizeString = sanitizeString; exports.initializeDatabases = initializeDatabases; +exports.scheduledEventOptimizeDatabases = scheduledEventOptimizeDatabases; exports.dbs = dbs; @@ -515,3 +516,15 @@ dbs.message.run( return cb(null); }, }; + +function scheduledEventOptimizeDatabases(args, cb) { + async.forEachSeries( + Object.keys(dbs), + (db, nextDb) => { + return db.run('PRAGMA OPTIMIZE', nextDb); + }, + err => { + return cb(err); + } + ); +}