Skip to content

Commit

Permalink
don't check for null content in consistency checks because it's too s…
Browse files Browse the repository at this point in the history
…low for large databases #2887
  • Loading branch information
zadam committed May 31, 2022
1 parent 93dd927 commit 339a6d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/services/backend_script_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ function BackendScriptApi(currentNote, apiParams) {
* @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
*/
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;
40 changes: 22 additions & 18 deletions src/services/consistency_checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,26 +367,30 @@ class ConsistencyChecks {
}
});

this.findAndFixIssues(`
SELECT notes.noteId, notes.type, notes.mime
FROM notes
JOIN note_contents USING (noteId)
WHERE isDeleted = 0
AND isProtected = 0
AND content IS NULL`,
({noteId, type, mime}) => {
if (this.autoFix) {
const note = becca.getNote(noteId);
const blankContent = getBlankContent(false, type, mime);
note.setContent(blankContent);
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.reloadNeeded = true;
this.findAndFixIssues(`
SELECT notes.noteId, notes.type, notes.mime
FROM notes
JOIN note_contents USING (noteId)
WHERE isDeleted = 0
AND isProtected = 0
AND content IS NULL`,
({noteId, type, mime}) => {
if (this.autoFix) {
const note = becca.getNote(noteId);
const blankContent = getBlankContent(false, type, mime);
note.setContent(blankContent);

logFix(`Note ${noteId} content was set to "${blankContent}" since it was null even though it is not deleted`);
} else {
logError(`Note ${noteId} content is null even though it is not deleted`);
}
});
this.reloadNeeded = true;

logFix(`Note ${noteId} content was set to "${blankContent}" since it was null even though it is not deleted`);
} else {
logError(`Note ${noteId} content is null even though it is not deleted`);
}
});
}

this.findAndFixIssues(`
SELECT note_revisions.noteRevisionId
Expand Down
9 changes: 7 additions & 2 deletions src/services/sql_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,18 @@ dbReady.then(() => {
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 = {
dbReady,
schemaExists,
isDbInitialized,
createInitialDatabase,
createDatabaseForSync,
setDbAsInitialized
setDbAsInitialized,
getDbSize
};

0 comments on commit 339a6d7

Please sign in to comment.