Optimize database and run quick check
This commit is contained in:
parent
b9248e04ed
commit
1fc7769f9f
2 changed files with 15 additions and 2 deletions
10
main.js
10
main.js
|
@ -121,6 +121,9 @@ const { Environment } = require('./ts/environment');
|
||||||
|
|
||||||
const sql = new MainSQL();
|
const sql = new MainSQL();
|
||||||
|
|
||||||
|
let sqlInitTimeStart = 0;
|
||||||
|
let sqlInitTimeEnd = 0;
|
||||||
|
|
||||||
let appStartInitialSpellcheckSetting = true;
|
let appStartInitialSpellcheckSetting = true;
|
||||||
|
|
||||||
const defaultWebPrefs = {
|
const defaultWebPrefs = {
|
||||||
|
@ -963,10 +966,12 @@ app.on('ready', async () => {
|
||||||
// from when it's first ready until the loading screen disappears.
|
// from when it's first ready until the loading screen disappears.
|
||||||
ipc.once('signal-app-loaded', () => {
|
ipc.once('signal-app-loaded', () => {
|
||||||
const loadTime = Date.now() - startTime;
|
const loadTime = Date.now() - startTime;
|
||||||
|
const sqlInitTime = sqlInitTimeEnd - sqlInitTimeStart;
|
||||||
console.log('App loaded - time:', loadTime);
|
console.log('App loaded - time:', loadTime);
|
||||||
|
console.log('SQL init - time:', sqlInitTime);
|
||||||
|
|
||||||
if (enableCI) {
|
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');
|
key = crypto.randomBytes(32).toString('hex');
|
||||||
userConfig.set('key', key);
|
userConfig.set('key', key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlInitTimeStart = Date.now();
|
||||||
const sqlInitPromise = sql.initialize({
|
const sqlInitPromise = sql.initialize({
|
||||||
configDir: userDataPath,
|
configDir: userDataPath,
|
||||||
key,
|
key,
|
||||||
|
@ -1074,6 +1081,7 @@ app.on('ready', async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await sqlInitPromise;
|
await sqlInitPromise;
|
||||||
|
sqlInitTimeEnd = Date.now();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('sql.initialize was unsuccessful; returning early');
|
console.log('sql.initialize was unsuccessful; returning early');
|
||||||
const buttonIndex = dialog.showMessageBoxSync({
|
const buttonIndex = dialog.showMessageBoxSync({
|
||||||
|
|
|
@ -313,7 +313,7 @@ function getSQLCipherIntegrityCheck(db: Database): Array<string> | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSQLIntegrityCheck(db: Database): 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') {
|
if (checkResult !== 'ok') {
|
||||||
return checkResult;
|
return checkResult;
|
||||||
}
|
}
|
||||||
|
@ -1618,6 +1618,11 @@ async function close(): Promise<void> {
|
||||||
|
|
||||||
const dbRef = globalInstance;
|
const dbRef = globalInstance;
|
||||||
globalInstance = undefined;
|
globalInstance = undefined;
|
||||||
|
|
||||||
|
// SQLLite documentation suggests that we run `PRAGMA optimize` right before
|
||||||
|
// closing the database connection.
|
||||||
|
dbRef.pragma('optimize');
|
||||||
|
|
||||||
dbRef.close();
|
dbRef.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue