don't check for null content in consistency checks because it's too slow for large databases #2887

This commit is contained in:
zadam 2022-05-31 14:09:46 +02:00
parent 93dd9274e7
commit 339a6d7817
3 changed files with 38 additions and 20 deletions

View File

@ -426,6 +426,15 @@ function BackendScriptApi(currentNote, apiParams) {
* @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version * @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
*/ */
this.getAppInfo = () => appInfo this.getAppInfo = () => appInfo
/**
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
*
* @type {{becca: Becca}}
*/
this.__private = {
becca
}
} }
module.exports = BackendScriptApi; module.exports = BackendScriptApi;

View File

@ -367,6 +367,9 @@ class ConsistencyChecks {
} }
}); });
if (sqlInit.getDbSize() < 500000) {
// querying for "content IS NULL" is expensive since content is not indexed. See e.g. https://github.com/zadam/trilium/issues/2887
this.findAndFixIssues(` this.findAndFixIssues(`
SELECT notes.noteId, notes.type, notes.mime SELECT notes.noteId, notes.type, notes.mime
FROM notes FROM notes
@ -387,6 +390,7 @@ class ConsistencyChecks {
logError(`Note ${noteId} content is null even though it is not deleted`); logError(`Note ${noteId} content is null even though it is not deleted`);
} }
}); });
}
this.findAndFixIssues(` this.findAndFixIssues(`
SELECT note_revisions.noteRevisionId SELECT note_revisions.noteRevisionId

View File

@ -178,7 +178,11 @@ dbReady.then(() => {
setInterval(() => optimize(), 10 * 60 * 60 * 1000); setInterval(() => optimize(), 10 * 60 * 60 * 1000);
}); });
log.info("DB size: " + sql.getValue("SELECT page_count * page_size / 1000 as size FROM pragma_page_count(), pragma_page_size()") + " KB"); function getDbSize() {
return sql.getValue("SELECT page_count * page_size / 1000 as size FROM pragma_page_count(), pragma_page_size()");
}
log.info(`DB size: ${getDbSize()} KB`);
module.exports = { module.exports = {
dbReady, dbReady,
@ -186,5 +190,6 @@ module.exports = {
isDbInitialized, isDbInitialized,
createInitialDatabase, createInitialDatabase,
createDatabaseForSync, createDatabaseForSync,
setDbAsInitialized setDbAsInitialized,
getDbSize
}; };