removed sourceId where it's not necessary (stored in CLS instead)

This commit is contained in:
azivner
2018-03-30 19:41:54 -04:00
parent 795d50f02e
commit 5d203b2278
16 changed files with 67 additions and 85 deletions

View File

@@ -38,8 +38,6 @@ async function cleanupSoftDeletedItems() {
}
async function cleanupUnusedImages() {
const sourceId = req.headers.source_id;
const unusedImageIds = await sql.getColumn(`
SELECT images.imageId
FROM images
@@ -56,7 +54,7 @@ async function cleanupUnusedImages() {
await sql.execute("UPDATE images SET isDeleted = 1, data = null, dateModified = ? WHERE imageId = ?",
[now, imageId]);
await sync_table.addImageSync(imageId, sourceId);
await sync_table.addImageSync(imageId);
}
}

View File

@@ -9,7 +9,6 @@ async function cloneNoteToParent(req) {
const parentNoteId = req.params.parentNoteId;
const childNoteId = req.params.childNoteId;
const prefix = req.body.prefix;
const sourceId = req.headers.source_id;
const validationResult = await tree.validateParentChild(parentNoteId, childNoteId);
@@ -33,7 +32,7 @@ async function cloneNoteToParent(req) {
await sql.replace("branches", branch);
await sync_table.addBranchSync(branch.branchId, sourceId);
await sync_table.addBranchSync(branch.branchId);
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
@@ -43,7 +42,6 @@ async function cloneNoteToParent(req) {
async function cloneNoteAfter(req) {
const noteId = req.params.noteId;
const afterBranchId = req.params.afterBranchId;
const sourceId = req.headers.source_id;
const afterNote = await tree.getBranch(afterBranchId);
@@ -58,7 +56,7 @@ async function cloneNoteAfter(req) {
await sql.execute("UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
[afterNote.parentNoteId, afterNote.notePosition]);
await sync_table.addNoteReorderingSync(afterNote.parentNoteId, sourceId);
await sync_table.addNoteReorderingSync(afterNote.parentNoteId);
const branch = {
branchId: utils.newBranchId(),
@@ -72,7 +70,7 @@ async function cloneNoteAfter(req) {
await sql.replace("branches", branch);
await sync_table.addBranchSync(branch.branchId, sourceId);
await sync_table.addBranchSync(branch.branchId);
return { success: true };
}

View File

@@ -6,7 +6,6 @@ const labels = require('../../services/labels');
const protected_session = require('../../services/protected_session');
async function uploadFile(req) {
const sourceId = req.headers.source_id;
const parentNoteId = req.params.parentNoteId;
const file = req.file;
const originalName = file.originalname;
@@ -25,10 +24,10 @@ async function uploadFile(req) {
isProtected: false,
type: 'file',
mime: file.mimetype
}, req, sourceId);
}, req);
await labels.createLabel(noteId, "original_file_name", originalName, sourceId);
await labels.createLabel(noteId, "file_size", size, sourceId);
await labels.createLabel(noteId, "original_file_name", originalName);
await labels.createLabel(noteId, "file_size", size);
return {
noteId: noteId

View File

@@ -22,7 +22,6 @@ async function returnImage(req, res) {
}
async function uploadImage(req) {
const sourceId = req.headers.source_id;
const noteId = req.query.noteId;
const file = req.file;
@@ -36,7 +35,7 @@ async function uploadImage(req) {
return [400, "Unknown image type: " + file.mimetype];
}
const {fileName, imageId} = await image.saveImage(file, sourceId, noteId);
const {fileName, imageId} = await image.saveImage(file, noteId);
return {
uploaded: true,

View File

@@ -91,7 +91,6 @@ async function parseImportFile(file) {
}
async function importTar(req) {
const sourceId = req.headers.source_id;
const parentNoteId = req.params.parentNoteId;
const file = req.file;
@@ -103,10 +102,10 @@ async function importTar(req) {
const files = await parseImportFile(file);
await importNotes(files, parentNoteId, sourceId);
await importNotes(files, parentNoteId);
}
async function importNotes(files, parentNoteId, sourceId) {
async function importNotes(files, parentNoteId) {
for (const file of files) {
if (file.meta.version !== 1) {
throw new Error("Can't read meta data version " + file.meta.version);
@@ -118,8 +117,7 @@ async function importNotes(files, parentNoteId, sourceId) {
const noteId = await notes.createNote(parentNoteId, file.meta.title, file.data, {
type: file.meta.type,
mime: file.meta.mime,
sourceId: sourceId
mime: file.meta.mime
});
for (const attr of file.meta.labels) {
@@ -127,7 +125,7 @@ async function importNotes(files, parentNoteId, sourceId) {
}
if (file.children.length > 0) {
await importNotes(file.children, noteId, sourceId);
await importNotes(file.children, noteId);
}
}
}

View File

@@ -31,11 +31,10 @@ async function getNote(req) {
}
async function createNote(req) {
const sourceId = req.headers.source_id;
const parentNoteId = req.params.parentNoteId;
const newNote = req.body;
const { noteId, branchId, note } = await notes.createNewNote(parentNoteId, newNote, req, sourceId);
const { noteId, branchId, note } = await notes.createNewNote(parentNoteId, newNote, req);
return {
'noteId': noteId,
@@ -47,39 +46,35 @@ async function createNote(req) {
async function updateNote(req) {
const note = req.body;
const noteId = req.params.noteId;
const sourceId = req.headers.source_id;
const dataKey = protected_session.getDataKey(req);
await notes.updateNote(noteId, note, dataKey, sourceId);
await notes.updateNote(noteId, note, dataKey);
}
async function sortNotes(req) {
const noteId = req.params.noteId;
const sourceId = req.headers.source_id;
const dataKey = protected_session.getDataKey(req);
await tree.sortNotesAlphabetically(noteId, dataKey, sourceId);
await tree.sortNotesAlphabetically(noteId, dataKey);
}
async function protectBranch(req) {
const noteId = req.params.noteId;
const isProtected = !!parseInt(req.params.isProtected);
const dataKey = protected_session.getDataKey(req);
const sourceId = req.headers.source_id;
await notes.protectNoteRecursively(noteId, dataKey, isProtected, sourceId);
await notes.protectNoteRecursively(noteId, dataKey, isProtected);
}
async function setNoteTypeMime(req) {
const noteId = req.params[0];
const type = req.params[1];
const mime = req.params[2];
const sourceId = req.headers.source_id;
await sql.execute("UPDATE notes SET type = ?, mime = ?, dateModified = ? WHERE noteId = ?",
[type, mime, utils.nowDate(), noteId]);
await sync_table.addNoteSync(noteId, sourceId);
await sync_table.addNoteSync(noteId);
}
module.exports = {

View File

@@ -24,7 +24,6 @@ async function getRecentNotes() {
async function addRecentNote(req) {
const branchId = req.params.branchId;
const notePath = req.params.notePath;
const sourceId = req.headers.source_id;
await sql.replace('recent_notes', {
branchId: branchId,
@@ -33,9 +32,9 @@ async function addRecentNote(req) {
isDeleted: 0
});
await sync_table.addRecentNoteSync(branchId, sourceId);
await sync_table.addRecentNoteSync(branchId);
await options.setOption('start_note_path', notePath, sourceId);
await options.setOption('start_note_path', notePath);
return await getRecentNotes();
}

View File

@@ -19,13 +19,12 @@ async function getAllowedSettings() {
async function updateSetting(req) {
const body = req.body;
const sourceId = req.headers.source_id;
if (!ALLOWED_OPTIONS.includes(body['name'])) {
return [400, "not allowed option to set"];
}
await options.setOption(body['name'], body['value'], sourceId);
await options.setOption(body['name'], body['value']);
}
module.exports = {

View File

@@ -62,13 +62,12 @@ async function getTree(req) {
async function setPrefix(req) {
const branchId = req.params.branchId;
const sourceId = req.headers.source_id;
const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix;
await sql.doInTransaction(async () => {
await sql.execute("UPDATE branches SET prefix = ?, dateModified = ? WHERE branchId = ?", [prefix, utils.nowDate(), branchId]);
await sync_table.addBranchSync(branchId, sourceId);
await sync_table.addBranchSync(branchId);
});
return {};

View File

@@ -14,7 +14,6 @@ const notes = require('../../services/notes');
async function moveBranchToParent(req) {
const branchId = req.params.branchId;
const parentNoteId = req.params.parentNoteId;
const sourceId = req.headers.source_id;
const noteToMove = await tree.getBranch(branchId);
@@ -32,7 +31,7 @@ async function moveBranchToParent(req) {
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[parentNoteId, newNotePos, now, branchId]);
await sync_table.addBranchSync(branchId, sourceId);
await sync_table.addBranchSync(branchId);
return { success: true };
}
@@ -40,7 +39,6 @@ async function moveBranchToParent(req) {
async function moveBranchBeforeNote(req) {
const branchId = req.params.branchId;
const beforeBranchId = req.params.beforeBranchId;
const sourceId = req.headers.source_id;
const noteToMove = await tree.getBranch(branchId);
const beforeNote = await tree.getBranch(beforeBranchId);
@@ -56,12 +54,12 @@ async function moveBranchBeforeNote(req) {
await sql.execute("UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
[beforeNote.parentNoteId, beforeNote.notePosition]);
await sync_table.addNoteReorderingSync(beforeNote.parentNoteId, sourceId);
await sync_table.addNoteReorderingSync(beforeNote.parentNoteId);
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[beforeNote.parentNoteId, beforeNote.notePosition, utils.nowDate(), branchId]);
await sync_table.addBranchSync(branchId, sourceId);
await sync_table.addBranchSync(branchId);
return { success: true };
}
@@ -69,7 +67,6 @@ async function moveBranchBeforeNote(req) {
async function moveBranchAfterNote(req) {
const branchId = req.params.branchId;
const afterBranchId = req.params.afterBranchId;
const sourceId = req.headers.source_id;
const noteToMove = await tree.getBranch(branchId);
const afterNote = await tree.getBranch(afterBranchId);
@@ -85,12 +82,12 @@ async function moveBranchAfterNote(req) {
await sql.execute("UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
[afterNote.parentNoteId, afterNote.notePosition]);
await sync_table.addNoteReorderingSync(afterNote.parentNoteId, sourceId);
await sync_table.addNoteReorderingSync(afterNote.parentNoteId);
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[afterNote.parentNoteId, afterNote.notePosition + 1, utils.nowDate(), branchId]);
await sync_table.addBranchSync(branchId, sourceId);
await sync_table.addBranchSync(branchId);
return { success: true };
}
@@ -104,7 +101,7 @@ async function setExpanded(req) {
}
async function deleteBranch(req) {
await notes.deleteNote(req.params.branchId, req.headers.source_id);
await notes.deleteNote(req.params.branchId);
}
module.exports = {