sync fixes

This commit is contained in:
azivner 2017-11-23 23:54:54 -05:00
parent f499872809
commit 1a36daa088
3 changed files with 8 additions and 8 deletions

View file

@ -2,7 +2,6 @@
"name": "trilium",
"description": "Trilium",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test-electron": "xo",

View file

@ -191,7 +191,6 @@ async function updateNote(noteId, newNote, ctx) {
//await sql.insert("links", link);
}
await sync_table.addNoteTreeSync(noteId);
await sync_table.addNoteSync(noteId);
});
}
@ -224,13 +223,13 @@ async function deleteNote(noteTreeId, browserId) {
const noteId = await sql.getSingleValue("SELECT note_id FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
const notDeletedNoteTreesCount = await sql.getSingleValue("SELECT COUNT(*) FROM notes_tree WHERE note_id = ?", [noteId]);
const notDeletedNoteTreesCount = await sql.getSingleValue("SELECT COUNT(*) FROM notes_tree WHERE note_id = ? AND is_deleted = 0", [noteId]);
if (!notDeletedNoteTreesCount) {
await sql.execute("UPDATE notes SET is_deleted = 1, date_modified = ? WHERE note_id = ?", [now, noteTreeId]);
await sync_table.addNoteSync(noteTreeId);
await sql.execute("UPDATE notes SET is_deleted = 1, date_modified = ? WHERE note_id = ?", [now, noteId]);
await sync_table.addNoteSync(noteId);
const children = await sql.getResults("SELECT note_tree_id FROM notes_tree WHERE note_pid = ? AND is_deleted = 0", [noteTreeId]);
const children = await sql.getResults("SELECT note_tree_id FROM notes_tree WHERE note_pid = ? AND is_deleted = 0", [noteId]);
for (const child of children) {
await deleteNote(child.note_tree_id, browserId);

View file

@ -121,10 +121,12 @@ async function pullSync(syncContext) {
continue;
}
console.log("Pulling ", sync);
const resp = await syncRequest(syncContext, 'GET', "/api/sync/" + sync.entity_name + "/" + encodeURIComponent(sync.entity_id));
if (!resp) {
log.error("Empty response to pull for " + sync.entity_name + ", id=" + sync.entity_id);
}
if (sync.entity_name === 'notes') {
await syncUpdate.updateNote(resp.entity, resp.links, syncContext.sourceId);
}