Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
measuring and logging time to compute content hash and consistency checks
azivner35859827586e
diff --git a/services/consistency_checks.js b/services/consistency_checks.jsindex 5d969aa9fe..2f95bd3fa2 100644--- a/services/consistency_checks.js+++ b/services/consistency_checks.js@@ -83,6 +83,8 @@ async function runSyncRowChecks(table, key, errorList) {async function runChecks() {const errorList = [];+ const startTime = new Date();+await runCheck(`SELECTnote_id@@ -170,13 +172,15 @@ async function runChecks() {await checkTreeCycles(errorList);}+ const elapsedTimeMs = new Date().getTime() - startTime.getTime();+if (errorList.length > 0) {- log.info("Consistency checks failed with these errors: " + JSON.stringify(errorList));+ log.info(`Consistency checks failed (took ${elapsedTimeMs}ms) with these errors: ` + JSON.stringify(errorList));messaging.sendMessageToAllClients({type: 'consistency-checks-failed'});}else {- log.info("All consistency checks passed.");+ log.info(`All consistency checks passed (took ${elapsedTimeMs}ms)`);}}diff --git a/services/content_hash.js b/services/content_hash.jsindex 35829ae46a..c6798026c5 100644--- a/services/content_hash.js+++ b/services/content_hash.js@@ -1,6 +1,7 @@const sql = require('./sql');const utils = require('./utils');const options = require('./options');+const log = require('./log');function getHash(rows) {let hash = '';@@ -13,9 +14,11 @@ function getHash(rows) {}async function getHashes() {+ const startTime = new Date();+const optionsQuestionMarks = Array(options.SYNCED_OPTIONS.length).fill('?').join(',');- return {+ const hashes = {notes: getHash(await sql.getAll(`SELECTnote_id,note_title,@@ -62,6 +65,12 @@ async function getHashes() {WHERE opt_name IN (${optionsQuestionMarks})ORDER BY opt_name`, options.SYNCED_OPTIONS))};++ const elapseTimeMs = new Date().getTime() - startTime.getTime();++ log.info(`Content hash computation took ${elapseTimeMs}ms`);++ return hashes;}module.exports = {