autocomplete cache gets updated with note update

This commit is contained in:
azivner 2018-04-18 23:11:30 -04:00
parent 834bfa39c7
commit bbf04209f0
2 changed files with 28 additions and 0 deletions

View file

@ -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 = {

View file

@ -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 DB
await 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,