diff --git a/routes/api/notes_move.js b/routes/api/notes_move.js index 1d5ce504f..6d392cf5f 100644 --- a/routes/api/notes_move.js +++ b/routes/api/notes_move.js @@ -38,13 +38,14 @@ router.put('/:noteTreeId/moveBefore/:beforeNoteTreeId', async (req, res, next) = await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos >= ? AND is_deleted = 0", [beforeNote.note_pid, beforeNote.note_pos]); + await sync_table.addNoteReorderingSync(beforeNote.note_pid); + const now = utils.nowTimestamp(); await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?", [beforeNote.note_pid, beforeNote.note_pos, now, noteTreeId]); await sync_table.addNoteTreeSync(noteTreeId); - await sync_table.addNoteReorderingSync(beforeNote.note_pid); }); res.send({}); @@ -66,13 +67,12 @@ router.put('/:noteTreeId/moveAfter/:afterNoteTreeId', async (req, res, next) => await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0", [afterNote.note_pid, afterNote.note_pos]); - const now = utils.nowTimestamp(); + await sync_table.addNoteReorderingSync(afterNote.note_pid); await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?", - [afterNote.note_pid, afterNote.note_pos + 1, now, noteTreeId]); + [afterNote.note_pid, afterNote.note_pos + 1, utils.nowTimestamp(), noteTreeId]); await sync_table.addNoteTreeSync(noteTreeId); - await sync_table.addNoteReorderingSync(afterNote.note_pid); }); res.send({}); @@ -157,6 +157,8 @@ router.put('/:noteId/cloneAfter/:afterNoteTreeId', async (req, res, next) => { await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0", [afterNote.note_pid, afterNote.note_pos]); + await sync_table.addNoteReorderingSync(afterNote.note_pid); + const noteTree = { 'note_tree_id': utils.newNoteTreeId(), 'note_id': noteId, @@ -170,7 +172,6 @@ router.put('/:noteId/cloneAfter/:afterNoteTreeId', async (req, res, next) => { await sql.replace("notes_tree", noteTree); await sync_table.addNoteTreeSync(noteTree.note_tree_id); - await sync_table.addNoteReorderingSync(afterNote.note_pid); res.send({ success: true @@ -204,6 +205,8 @@ router.put('/:noteTreeId/expanded/:expanded', async (req, res, next) => { await sql.doInTransaction(async () => { await sql.execute("UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]); + + // we don't sync expanded attribute }); res.send({}); diff --git a/services/notes.js b/services/notes.js index 8b817dd84..c54f0dfe3 100644 --- a/services/notes.js +++ b/services/notes.js @@ -24,13 +24,13 @@ async function createNewNote(parentNoteId, note) { await sql.execute('UPDATE notes_tree SET note_pos = note_pos + 1, date_modified = ? WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0', [utils.nowTimestamp(), parentNoteId, afterNote.note_pos]); + + await sync_table.addNoteReorderingSync(parentNoteId); } else { throw new Error('Unknown target: ' + note.target); } - await sync_table.addNoteTreeSync(noteTreeId); - await sync_table.addNoteSync(noteId); const now = utils.nowTimestamp(); @@ -43,6 +43,8 @@ async function createNewNote(parentNoteId, note) { 'is_protected': note.is_protected }); + await sync_table.addNoteSync(noteId); + await sql.insert("notes_tree", { 'note_tree_id': noteTreeId, 'note_id': noteId, @@ -52,6 +54,8 @@ async function createNewNote(parentNoteId, note) { 'date_modified': now, 'is_deleted': 0 }); + + await sync_table.addNoteTreeSync(noteTreeId); }); return { @@ -177,6 +181,7 @@ async function updateNote(noteId, newNote, ctx) { async function deleteNote(noteTreeId) { const now = utils.nowTimestamp(); + await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]); await sync_table.addNoteTreeSync(noteTreeId); diff --git a/services/options.js b/services/options.js index dbdcbfaab..c6e236e21 100644 --- a/services/options.js +++ b/services/options.js @@ -20,13 +20,8 @@ async function setOption(optName, optValue) { await sync_table.addOptionsSync(optName); } - await setOptionNoSync(optName, optValue); -} - -async function setOptionNoSync(optName, optValue) { - const now = utils.nowTimestamp(); - - await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?", [optValue, now, optName]); + await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?", + [optValue, utils.nowTimestamp(), optName]); } sql.dbReady.then(async () => { diff --git a/services/sql.js b/services/sql.js index cc48d3e85..49d867999 100644 --- a/services/sql.js +++ b/services/sql.js @@ -104,10 +104,6 @@ async function executeScript(query) { return await wrap(async db => db.exec(query)); } -async function remove(tableName, noteId) { - return await execute("DELETE FROM " + tableName + " WHERE note_id = ?", [noteId]); -} - async function wrap(func) { const thisError = new Error(); const db = await dbReady; @@ -187,6 +183,5 @@ module.exports = { getFlattenedResults, execute, executeScript, - remove, doInTransaction }; \ No newline at end of file