separate DB connection for each transaction (just for the record, will be reverted probably)

This commit is contained in:
azivner
2017-11-28 17:04:47 -05:00
parent 4d95eb0762
commit fd764f6163
21 changed files with 326 additions and 429 deletions

View File

@@ -16,11 +16,11 @@ router.put('/:noteTreeId/moveTo/:parentNoteId', auth.checkApiAuth, async (req, r
const now = utils.nowTimestamp();
await sql.doInTransaction(async () => {
await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
await sql.doInTransaction(async db => {
await sql.execute(db, "UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
[parentNoteId, newNotePos, now, noteTreeId]);
await sync_table.addNoteTreeSync(noteTreeId);
await sync_table.addNoteTreeSync(db, noteTreeId);
});
res.send({});
@@ -33,18 +33,18 @@ router.put('/:noteTreeId/moveBefore/:beforeNoteTreeId', async (req, res, next) =
const beforeNote = await sql.getSingleResult("SELECT * FROM notes_tree WHERE note_tree_id = ?", [beforeNoteTreeId]);
if (beforeNote) {
await sql.doInTransaction(async () => {
await sql.doInTransaction(async db => {
// we don't change date_modified so other changes are prioritized in case of conflict
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(db, "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]);
const now = utils.nowTimestamp();
await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
await sql.execute(db, "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);
await sync_table.addNoteTreeSync(db, noteTreeId);
await sync_table.addNoteReorderingSync(db, beforeNote.note_pid);
});
res.send({});
@@ -61,18 +61,18 @@ router.put('/:noteTreeId/moveAfter/:afterNoteTreeId', async (req, res, next) =>
const afterNote = await sql.getSingleResult("SELECT * FROM notes_tree WHERE note_tree_id = ?", [afterNoteTreeId]);
if (afterNote) {
await sql.doInTransaction(async () => {
await sql.doInTransaction(async db => {
// we don't change date_modified so other changes are prioritized in case of conflict
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(db, "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 sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
await sql.execute(db, "UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?",
[afterNote.note_pid, afterNote.note_pos + 1, now, noteTreeId]);
await sync_table.addNoteTreeSync(noteTreeId);
await sync_table.addNoteReorderingSync(afterNote.note_pid);
await sync_table.addNoteTreeSync(db, noteTreeId);
await sync_table.addNoteReorderingSync(db, afterNote.note_pid);
});
res.send({});
@@ -105,7 +105,7 @@ router.put('/:childNoteId/cloneTo/:parentNoteId', auth.checkApiAuth, async (req,
const maxNotePos = await sql.getSingleValue('SELECT MAX(note_pos) FROM notes_tree WHERE note_pid = ? AND is_deleted = 0', [parentNoteId]);
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1;
await sql.doInTransaction(async () => {
await sql.doInTransaction(async db => {
const noteTree = {
'note_tree_id': utils.newNoteTreeId(),
'note_id': childNoteId,
@@ -116,9 +116,9 @@ router.put('/:childNoteId/cloneTo/:parentNoteId', auth.checkApiAuth, async (req,
'is_deleted': 0
};
await sql.replace("notes_tree", noteTree);
await sql.replace(db, "notes_tree", noteTree);
await sync_table.addNoteTreeSync(noteTree.note_tree_id);
await sync_table.addNoteTreeSync(db, noteTree.note_tree_id);
res.send({
success: true
@@ -152,9 +152,9 @@ router.put('/:noteId/cloneAfter/:afterNoteTreeId', async (req, res, next) => {
});
}
await sql.doInTransaction(async () => {
await sql.doInTransaction(async db => {
// we don't change date_modified so other changes are prioritized in case of conflict
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(db, "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 noteTree = {
@@ -167,10 +167,10 @@ router.put('/:noteId/cloneAfter/:afterNoteTreeId', async (req, res, next) => {
'is_deleted': 0
};
await sql.replace("notes_tree", noteTree);
await sql.replace(db, "notes_tree", noteTree);
await sync_table.addNoteTreeSync(noteTree.note_tree_id);
await sync_table.addNoteReorderingSync(afterNote.note_pid);
await sync_table.addNoteTreeSync(db, noteTree.note_tree_id);
await sync_table.addNoteReorderingSync(db, afterNote.note_pid);
res.send({
success: true
@@ -202,8 +202,8 @@ router.put('/:noteTreeId/expanded/:expanded', async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
const expanded = req.params.expanded;
await sql.doInTransaction(async () => {
await sql.execute("UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]);
await sql.doInTransaction(async db => {
await sql.execute(db, "UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]);
});
res.send({});