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
sync changes for note_tree_id and fixed recent notes
azivner9a819cafed52
diff --git a/public/javascripts/dialogs/recent_notes.js b/public/javascripts/dialogs/recent_notes.jsindex d5bd7d1136..4278aece22 100644--- a/public/javascripts/dialogs/recent_notes.js+++ b/public/javascripts/dialogs/recent_notes.js@@ -18,8 +18,11 @@ const recentNotes = (function() {function addRecentNote(noteTreeId) {setTimeout(() => {+ console.log("note tree: " + noteTreeId);+ console.log("current note tree: " + noteTree.getCurrentNoteTreeId());+// we include the note into recent list only if the user stayed on the note at least 5 seconds- if (noteTreeId === noteEditor.getCurrentNoteId()) {+ if (noteTreeId === noteTree.getCurrentNoteTreeId()) {$.ajax({url: baseApiUrl + 'recent-notes/' + noteTreeId,type: 'PUT',diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.jsindex 2e8fd2ec57..835215e743 100644--- a/public/javascripts/note_tree.js+++ b/public/javascripts/note_tree.js@@ -317,7 +317,7 @@ const noteTree = (function() {function getCurrentNoteTreeId() {const node = getCurrentNode();- return node.note_tree_id;+ return node.data.note_tree_id;}function setCurrentNoteTreeBasedOnProtectedStatus() {diff --git a/routes/api/sync.js b/routes/api/sync.jsindex 1354fdfd8a..9bddbca200 100644--- a/routes/api/sync.js+++ b/routes/api/sync.js@@ -50,12 +50,12 @@ router.get('/options/:optName', auth.checkApiAuth, async (req, res, next) => {}});-router.get('/notes_reordering/:noteParentId', auth.checkApiAuth, async (req, res, next) => {- const noteParentId = req.params.noteParentId;+router.get('/notes_reordering/:noteTreeParentId', auth.checkApiAuth, async (req, res, next) => {+ const noteTreeParentId = req.params.noteTreeParentId;res.send({- note_pid: noteParentId,- ordering: await sql.getMap("SELECT note_id, note_pos FROM notes_tree WHERE note_pid = ?", [noteParentId])+ note_pid: noteTreeParentId,+ ordering: await sql.getMap("SELECT note_tree_id, note_pos FROM notes_tree WHERE note_pid = ?", [noteTreeParentId])});});diff --git a/services/sync.js b/services/sync.jsindex f73d4032f6..4a13080a8f 100644--- a/services/sync.js+++ b/services/sync.js@@ -179,7 +179,7 @@ async function readAndPushEntity(sync, syncContext) {entity = await sql.getSingleResult('SELECT * FROM notes WHERE note_id = ?', [sync.entity_id]);}else if (sync.entity_name === 'notes_tree') {- entity = await sql.getSingleResult('SELECT * FROM notes_tree WHERE note_id = ?', [sync.entity_id]);+ entity = await sql.getSingleResult('SELECT * FROM notes_tree WHERE note_tree_id = ?', [sync.entity_id]);}else if (sync.entity_name === 'notes_history') {entity = await sql.getSingleResult('SELECT * FROM notes_history WHERE note_history_id = ?', [sync.entity_id]);@@ -187,14 +187,14 @@ async function readAndPushEntity(sync, syncContext) {else if (sync.entity_name === 'notes_reordering') {entity = {note_pid: sync.entity_id,- ordering: await sql.getMap('SELECT note_id, note_pos FROM notes_tree WHERE note_pid = ?', [sync.entity_id])+ ordering: await sql.getMap('SELECT note_tree_id, note_pos FROM notes_tree WHERE note_pid = ?', [sync.entity_id])};}else if (sync.entity_name === 'options') {entity = await sql.getSingleResult('SELECT * FROM options WHERE opt_name = ?', [sync.entity_id]);}else if (sync.entity_name === 'recent_notes') {- entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_id = ?', [sync.entity_id]);+ entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_tree_id = ?', [sync.entity_id]);}else {throw new Error("Unrecognized entity type " + sync.entity_name);diff --git a/services/sync_table.js b/services/sync_table.jsindex b0f8fc71bf..6cebc62af0 100644--- a/services/sync_table.js+++ b/services/sync_table.js@@ -6,12 +6,12 @@ async function addNoteSync(noteId, sourceId) {await addEntitySync("notes", noteId, sourceId)}-async function addNoteTreeSync(noteId, sourceId) {- await addEntitySync("notes_tree", noteId, sourceId)+async function addNoteTreeSync(noteTreeId, sourceId) {+ await addEntitySync("notes_tree", noteTreeId, sourceId)}-async function addNoteReorderingSync(parentNoteId, sourceId) {- await addEntitySync("notes_reordering", parentNoteId, sourceId)+async function addNoteReorderingSync(parentNoteTreeId, sourceId) {+ await addEntitySync("notes_reordering", parentNoteTreeId, sourceId)}async function addNoteHistorySync(noteHistoryId, sourceId) {diff --git a/services/sync_update.js b/services/sync_update.jsindex fb849b899d..b590f606fa 100644--- a/services/sync_update.js+++ b/services/sync_update.js@@ -35,7 +35,7 @@ async function updateNote(entity, links, sourceId) {}async function updateNoteTree(entity, sourceId) {- const orig = await sql.getSingleResultOrNull("select * from notes_tree where note_id = ?", [entity.note_id]);+ const orig = await sql.getSingleResultOrNull("select * from notes_tree where note_tree_id = ?", [entity.note_tree_id]);if (orig === null || orig.date_modified < entity.date_modified) {await sql.doInTransaction(async () => {@@ -43,15 +43,16 @@ async function updateNoteTree(entity, sourceId) {await sql.replace('notes_tree', entity);- await sync_table.addNoteTreeSync(entity.note_id, sourceId);+ await sync_table.addNoteTreeSync(entity.note_tree_id, sourceId);+ // not sure why this is here ...await sql.addAudit(audit_category.UPDATE_TITLE, sourceId, entity.note_id);});- log.info("Update/sync note tree " + entity.note_id);+ log.info("Update/sync note tree " + entity.note_tree_id);}else {- await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note tree <note>, " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));+ await eventLog.addNoteEvent(entity.note_tree_id, "Sync conflict in note tree <note>, " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));}}@@ -75,7 +76,7 @@ async function updateNoteHistory(entity, sourceId) {async function updateNoteReordering(entity, sourceId) {await sql.doInTransaction(async () => {Object.keys(entity.ordering).forEach(async key => {- await sql.execute("UPDATE notes_tree SET note_pos = ? WHERE note_id = ?", [entity.ordering[key], key]);+ await sql.execute("UPDATE notes_tree SET note_pos = ? WHERE note_tree_id = ?", [entity.ordering[key], key]);});await sync_table.addNoteReorderingSync(entity.note_pid, sourceId);@@ -105,7 +106,7 @@ async function updateOptions(entity, sourceId) {}async function updateRecentNotes(entity, sourceId) {- const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_id = ?", [entity.note_id]);+ const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_tree_id = ?", [entity.note_tree_id]);if (orig === null || orig.date_accessed < entity.date_accessed) {await sql.doInTransaction(async () => {