cosmetic sync related changes

This commit is contained in:
azivner 2017-11-29 21:04:30 -05:00
parent 6d603eda86
commit e6629b2c93
4 changed files with 17 additions and 19 deletions

View File

@ -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({});

View File

@ -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);

View File

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

View File

@ -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
};