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 / transaction fixes for recent notes
azivnerf799d3076bcd
diff --git a/public/javascripts/dialogs/recent_notes.js b/public/javascripts/dialogs/recent_notes.jsindex bf91328ebb..2f078fa5af 100644--- a/public/javascripts/dialogs/recent_notes.js+++ b/public/javascripts/dialogs/recent_notes.js@@ -21,7 +21,7 @@ const recentNotes = (function() {function addRecentNote(notePath) {setTimeout(() => {// we include the note into recent list only if the user stayed on the note at least 5 seconds- if (notePath === noteTree.getCurrentNotePath()) {+ if (notePath && notePath === noteTree.getCurrentNotePath()) {$.ajax({url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePath),type: 'PUT',diff --git a/routes/api/recent_notes.js b/routes/api/recent_notes.jsindex 9b106119bd..d2accd4d90 100644--- a/routes/api/recent_notes.js+++ b/routes/api/recent_notes.js@@ -15,23 +15,29 @@ router.get('', auth.checkApiAuth, async (req, res, next) => {router.put('/:notePath', auth.checkApiAuth, async (req, res, next) => {const notePath = req.params.notePath;- await sql.replace('recent_notes', {- note_path: notePath,- date_accessed: utils.nowTimestamp(),- is_deleted: 0- });+ await sql.doInTransaction(async() => {+ await sql.replace('recent_notes', {+ note_path: notePath,+ date_accessed: utils.nowTimestamp(),+ is_deleted: 0+ });- await sync_table.addRecentNoteSync(notePath);+ await sync_table.addRecentNoteSync(notePath);- await options.setOption('start_note_tree_id', notePath);+ await options.setOption('start_note_tree_id', notePath);+ });res.send(await getRecentNotes());});router.delete('/:notePath', auth.checkApiAuth, async (req, res, next) => {- await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_path = ?', [req.params.notePath]);+ const notePath = req.params.notePath;- await sync_table.addRecentNoteSync(req.params.notePath);+ await sql.doInTransaction(async() => {+ await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_path = ?', [notePath]);++ await sync_table.addRecentNoteSync(notePath);+ });res.send(await getRecentNotes());});