Optimize database and run quick check

This commit is contained in:
Fedor Indutny 2021-04-06 10:29:22 -07:00 committed by Josh Perez
parent b9248e04ed
commit 1fc7769f9f
2 changed files with 15 additions and 2 deletions

10
main.js
View File

@ -121,6 +121,9 @@ const { Environment } = require('./ts/environment');
const sql = new MainSQL();
let sqlInitTimeStart = 0;
let sqlInitTimeEnd = 0;
let appStartInitialSpellcheckSetting = true;
const defaultWebPrefs = {
@ -963,10 +966,12 @@ app.on('ready', async () => {
// from when it's first ready until the loading screen disappears.
ipc.once('signal-app-loaded', () => {
const loadTime = Date.now() - startTime;
const sqlInitTime = sqlInitTimeEnd - sqlInitTimeStart;
console.log('App loaded - time:', loadTime);
console.log('SQL init - time:', sqlInitTime);
if (enableCI) {
console._log('ci: app_loaded=%j', { loadTime });
console._log('ci: app_loaded=%j', { loadTime, sqlInitTime });
}
});
@ -1027,6 +1032,8 @@ app.on('ready', async () => {
key = crypto.randomBytes(32).toString('hex');
userConfig.set('key', key);
}
sqlInitTimeStart = Date.now();
const sqlInitPromise = sql.initialize({
configDir: userDataPath,
key,
@ -1074,6 +1081,7 @@ app.on('ready', async () => {
try {
await sqlInitPromise;
sqlInitTimeEnd = Date.now();
} catch (error) {
console.log('sql.initialize was unsuccessful; returning early');
const buttonIndex = dialog.showMessageBoxSync({

View File

@ -313,7 +313,7 @@ function getSQLCipherIntegrityCheck(db: Database): Array<string> | undefined {
}
function getSQLIntegrityCheck(db: Database): string | undefined {
const checkResult = db.pragma('integrity_check', { simple: true });
const checkResult = db.pragma('quick_check', { simple: true });
if (checkResult !== 'ok') {
return checkResult;
}
@ -1618,6 +1618,11 @@ async function close(): Promise<void> {
const dbRef = globalInstance;
globalInstance = undefined;
// SQLLite documentation suggests that we run `PRAGMA optimize` right before
// closing the database connection.
dbRef.pragma('optimize');
dbRef.close();
}