mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	cosmetic sync related changes
This commit is contained in:
		
							parent
							
								
									6d603eda86
								
							
						
					
					
						commit
						e6629b2c93
					
				@ -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",
 | 
					            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]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await sync_table.addNoteReorderingSync(beforeNote.note_pid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const now = utils.nowTimestamp();
 | 
					            const now = utils.nowTimestamp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
 | 
					            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]);
 | 
					                [beforeNote.note_pid, beforeNote.note_pos, now, noteTreeId]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await sync_table.addNoteTreeSync(noteTreeId);
 | 
					            await sync_table.addNoteTreeSync(noteTreeId);
 | 
				
			||||||
            await sync_table.addNoteReorderingSync(beforeNote.note_pid);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        res.send({});
 | 
					        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",
 | 
					            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]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            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 = ?",
 | 
					            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.addNoteTreeSync(noteTreeId);
 | 
				
			||||||
            await sync_table.addNoteReorderingSync(afterNote.note_pid);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        res.send({});
 | 
					        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",
 | 
					        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]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await sync_table.addNoteReorderingSync(afterNote.note_pid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const noteTree = {
 | 
					        const noteTree = {
 | 
				
			||||||
            'note_tree_id': utils.newNoteTreeId(),
 | 
					            'note_tree_id': utils.newNoteTreeId(),
 | 
				
			||||||
            'note_id': noteId,
 | 
					            'note_id': noteId,
 | 
				
			||||||
@ -170,7 +172,6 @@ router.put('/:noteId/cloneAfter/: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);
 | 
					        await sync_table.addNoteTreeSync(noteTree.note_tree_id);
 | 
				
			||||||
        await sync_table.addNoteReorderingSync(afterNote.note_pid);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        res.send({
 | 
					        res.send({
 | 
				
			||||||
            success: true
 | 
					            success: true
 | 
				
			||||||
@ -204,6 +205,8 @@ router.put('/:noteTreeId/expanded/:expanded', async (req, res, next) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    await sql.doInTransaction(async () => {
 | 
					    await sql.doInTransaction(async () => {
 | 
				
			||||||
        await sql.execute("UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]);
 | 
					        await sql.execute("UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // we don't sync expanded attribute
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.send({});
 | 
					    res.send({});
 | 
				
			||||||
 | 
				
			|||||||
@ -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',
 | 
					            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]);
 | 
					                [utils.nowTimestamp(), parentNoteId, afterNote.note_pos]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await sync_table.addNoteReorderingSync(parentNoteId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            throw new Error('Unknown target: ' + note.target);
 | 
					            throw new Error('Unknown target: ' + note.target);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await sync_table.addNoteTreeSync(noteTreeId);
 | 
					 | 
				
			||||||
        await sync_table.addNoteSync(noteId);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const now = utils.nowTimestamp();
 | 
					        const now = utils.nowTimestamp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,6 +43,8 @@ async function createNewNote(parentNoteId, note) {
 | 
				
			|||||||
            'is_protected': note.is_protected
 | 
					            'is_protected': note.is_protected
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await sync_table.addNoteSync(noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await sql.insert("notes_tree", {
 | 
					        await sql.insert("notes_tree", {
 | 
				
			||||||
            'note_tree_id': noteTreeId,
 | 
					            'note_tree_id': noteTreeId,
 | 
				
			||||||
            'note_id': noteId,
 | 
					            'note_id': noteId,
 | 
				
			||||||
@ -52,6 +54,8 @@ async function createNewNote(parentNoteId, note) {
 | 
				
			|||||||
            'date_modified': now,
 | 
					            'date_modified': now,
 | 
				
			||||||
            'is_deleted': 0
 | 
					            'is_deleted': 0
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await sync_table.addNoteTreeSync(noteTreeId);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
@ -177,6 +181,7 @@ async function updateNote(noteId, newNote, ctx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
async function deleteNote(noteTreeId) {
 | 
					async function deleteNote(noteTreeId) {
 | 
				
			||||||
    const now = utils.nowTimestamp();
 | 
					    const now = utils.nowTimestamp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]);
 | 
					    await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]);
 | 
				
			||||||
    await sync_table.addNoteTreeSync(noteTreeId);
 | 
					    await sync_table.addNoteTreeSync(noteTreeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,13 +20,8 @@ async function setOption(optName, optValue) {
 | 
				
			|||||||
        await sync_table.addOptionsSync(optName);
 | 
					        await sync_table.addOptionsSync(optName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await setOptionNoSync(optName, optValue);
 | 
					    await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?",
 | 
				
			||||||
}
 | 
					        [optValue, utils.nowTimestamp(), optName]);
 | 
				
			||||||
 | 
					 | 
				
			||||||
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]);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sql.dbReady.then(async () => {
 | 
					sql.dbReady.then(async () => {
 | 
				
			||||||
 | 
				
			|||||||
@ -104,10 +104,6 @@ async function executeScript(query) {
 | 
				
			|||||||
    return await wrap(async db => db.exec(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) {
 | 
					async function wrap(func) {
 | 
				
			||||||
    const thisError = new Error();
 | 
					    const thisError = new Error();
 | 
				
			||||||
    const db = await dbReady;
 | 
					    const db = await dbReady;
 | 
				
			||||||
@ -187,6 +183,5 @@ module.exports = {
 | 
				
			|||||||
    getFlattenedResults,
 | 
					    getFlattenedResults,
 | 
				
			||||||
    execute,
 | 
					    execute,
 | 
				
			||||||
    executeScript,
 | 
					    executeScript,
 | 
				
			||||||
    remove,
 | 
					 | 
				
			||||||
    doInTransaction
 | 
					    doInTransaction
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user