Add method for optimizing DBs

This commit is contained in:
Bryan Ashby 2020-12-11 14:58:00 -07:00
parent 6bae3f7050
commit 878e73e5d7
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@ exports.nextConf = nextConf;
exports.prevArea = prevArea;
exports.nextArea = nextArea;
exports.sendForgotPasswordEmail = sendForgotPasswordEmail;
exports.optimizeDatabases = optimizeDatabases;
const handleAuthFailures = (callingMenu, err, cb) => {
// already logged in with this user?
@ -205,3 +206,25 @@ function sendForgotPasswordEmail(callingMenu, formData, extraArgs, cb) {
return logoff(callingMenu, formData, extraArgs, cb);
});
}
function optimizeDatabases(callingMenu, formData, extraArgs, cb) {
const dbs = require('./database').dbs;
const client = callingMenu.client;
client.term.write('\r\n\r\n');
Object.keys(dbs).forEach(dbName => {
client.log.info({ dbName }, 'Optimizing database');
client.term.write(`Optimizing ${dbName}. Please wait...\r\n`);
// https://www.sqlite.org/pragma.html#pragma_optimize
dbs[dbName].run('PRAGMA optimize;', err => {
if (err) {
client.log.error({ error : err, dbName }, 'Error attempting to optimize database');
}
});
});
return callingMenu.prevMenu(cb);
}