fix sync of date_modified in notes_tree which caused failed hash check

This commit is contained in:
azivner 2017-12-18 20:58:13 -05:00
parent f96e38fd13
commit 1b900bb907
3 changed files with 12 additions and 8 deletions

View File

@ -37,6 +37,7 @@ router.put('/:noteTreeId/move-before/:beforeNoteTreeId', async (req, res, next)
if (beforeNote) { if (beforeNote) {
await sql.doInTransaction(async () => { await sql.doInTransaction(async () => {
// we don't change date_modified so other changes are prioritized in case of conflict // we don't change date_modified so other changes are prioritized in case of conflict
// also we would have to sync all those modified note trees otherwise hash checks would fail
await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos >= ? AND is_deleted = 0", 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]); [beforeNote.note_pid, beforeNote.note_pos]);
@ -67,6 +68,7 @@ router.put('/:noteTreeId/move-after/:afterNoteTreeId', async (req, res, next) =>
if (afterNote) { if (afterNote) {
await sql.doInTransaction(async () => { await sql.doInTransaction(async () => {
// we don't change date_modified so other changes are prioritized in case of conflict // we don't change date_modified so other changes are prioritized in case of conflict
// also we would have to sync all those modified note trees otherwise hash checks would fail
await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0", 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]); [afterNote.note_pid, afterNote.note_pos]);
@ -123,11 +125,11 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (req
await sql.replace("notes_tree", noteTree); await sql.replace("notes_tree", noteTree);
await sync_table.addNoteTreeSync(noteTree.note_tree_id, sourceId); await sync_table.addNoteTreeSync(noteTree.note_tree_id, sourceId);
});
res.send({ res.send({
success: true success: true
}); });
});
}); });
router.put('/:noteId/clone-after/:afterNoteTreeId', async (req, res, next) => { router.put('/:noteId/clone-after/:afterNoteTreeId', async (req, res, next) => {
@ -159,6 +161,7 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', async (req, res, next) => {
await sql.doInTransaction(async () => { await sql.doInTransaction(async () => {
// we don't change date_modified so other changes are prioritized in case of conflict // we don't change date_modified so other changes are prioritized in case of conflict
// also we would have to sync all those modified note trees otherwise hash checks would fail
await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0", 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]); [afterNote.note_pid, afterNote.note_pos]);
@ -177,11 +180,11 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', async (req, res, next) => {
await sql.replace("notes_tree", noteTree); await sql.replace("notes_tree", noteTree);
await sync_table.addNoteTreeSync(noteTree.note_tree_id, sourceId); await sync_table.addNoteTreeSync(noteTree.note_tree_id, sourceId);
});
res.send({ res.send({
success: true success: true
}); });
});
}); });
async function checkCycle(parentNoteId, childNoteId) { async function checkCycle(parentNoteId, childNoteId) {

View File

@ -1 +1 @@
module.exports = { build_date:"2017-12-17T16:57:13-05:00", build_revision: "125012cba779086e526fa763cb0bfde59451fda6" }; module.exports = { build_date:"2017-12-18T00:01:16-05:00", build_revision: "f96e38fd13152eee4700ead265c5b255b8e6853e" };

View File

@ -22,7 +22,8 @@ async function createNewNote(parentNoteId, note, sourceId) {
newNotePos = afterNote.note_pos + 1; newNotePos = afterNote.note_pos + 1;
await sql.execute('UPDATE notes_tree SET note_pos = note_pos + 1, date_modified = ? WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0', // not updating date_modified to avoig having to sync whole rows
await sql.execute('UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0',
[utils.nowDate(), parentNoteId, afterNote.note_pos]); [utils.nowDate(), parentNoteId, afterNote.note_pos]);
await sync_table.addNoteReorderingSync(parentNoteId, sourceId); await sync_table.addNoteReorderingSync(parentNoteId, sourceId);