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
autocomplete cache gets updated with note update
azivnerbbf04209f0d6
diff --git a/src/services/autocomplete.js b/src/services/autocomplete.jsindex 43f0820caa..e815d5eb30 100644--- a/src/services/autocomplete.js+++ b/src/services/autocomplete.js@@ -1,5 +1,7 @@const sql = require('./sql');const sqlInit = require('./sql_init');+const syncTableService = require('./sync_table');+const repository = require('./repository');let noteTitles;let noteIds;@@ -114,6 +116,20 @@ function getNoteTitle(path) {return titles.join(' / ');}+syncTableService.addListener(async (entityName, entityId) => {+ if (entityName === 'notes') {+ const note = await repository.getNote(entityId);++ if (note.isDeleted) {+ delete noteTitles[note.noteId];+ delete childToParent[note.noteId];+ }+ else {+ noteTitles[note.noteId] = note.title;+ }+ }+});+sqlInit.dbReady.then(load);module.exports = {diff --git a/src/services/sync_table.js b/src/services/sync_table.jsindex 7ba8f52129..e2c70ccf09 100644--- a/src/services/sync_table.js+++ b/src/services/sync_table.js@@ -5,6 +5,12 @@ const syncSetup = require('./sync_setup');const log = require('./log');const cls = require('./cls');+const listeners = [];++function addListener(listener) {+ listeners.push(listener);+}+async function addNoteSync(noteId, sourceId) {await addEntitySync("notes", noteId, sourceId)}@@ -58,6 +64,11 @@ async function addEntitySync(entityName, entityId, sourceId) {// useful when you fork the DB for new "client" instance, it won't try to sync the whole DBawait sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('lastSyncedPush', 'lastSyncedPull')");}++ for (const listener of listeners) {+ // not awaiting to not block the execution+ listener(entityName, entityId);+ }}async function cleanupSyncRowsForMissingEntities(entityName, entityKey) {@@ -104,6 +115,7 @@ async function fillAllSyncRows() {}module.exports = {+ addListener,addNoteSync,addBranchSync,addNoteReorderingSync,