mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 18:25:51 +01:00
removed sourceId where it's not necessary (stored in CLS instead)
This commit is contained in:
@@ -11,7 +11,7 @@ const jimp = require('jimp');
|
||||
const imageType = require('image-type');
|
||||
const sanitizeFilename = require('sanitize-filename');
|
||||
|
||||
async function saveImage(file, sourceId, noteId) {
|
||||
async function saveImage(file, noteId) {
|
||||
const resizedImage = await resize(file.buffer);
|
||||
const optimizedImage = await optimize(resizedImage);
|
||||
|
||||
@@ -35,7 +35,7 @@ async function saveImage(file, sourceId, noteId) {
|
||||
dateCreated: now
|
||||
});
|
||||
|
||||
await sync_table.addImageSync(imageId, sourceId);
|
||||
await sync_table.addImageSync(imageId);
|
||||
|
||||
const noteImageId = utils.newNoteImageId();
|
||||
|
||||
@@ -48,7 +48,7 @@ async function saveImage(file, sourceId, noteId) {
|
||||
dateCreated: now
|
||||
});
|
||||
|
||||
await sync_table.addNoteImageSync(noteImageId, sourceId);
|
||||
await sync_table.addNoteImageSync(noteImageId);
|
||||
});
|
||||
return {fileName, imageId};
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ async function getNoteIdsWithLabel(name) {
|
||||
WHERE notes.isDeleted = 0 AND labels.isDeleted = 0 AND labels.name = ? AND labels.isDeleted = 0`, [name]);
|
||||
}
|
||||
|
||||
async function createLabel(noteId, name, value = "", sourceId = null) {
|
||||
async function createLabel(noteId, name, value = "") {
|
||||
if (value === null || value === undefined) {
|
||||
value = "";
|
||||
}
|
||||
@@ -75,7 +75,7 @@ async function createLabel(noteId, name, value = "", sourceId = null) {
|
||||
isDeleted: false
|
||||
});
|
||||
|
||||
await sync_table.addLabelSync(labelId, sourceId);
|
||||
await sync_table.addLabelSync(labelId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -5,7 +5,7 @@ const sync_table = require('./sync_table');
|
||||
const labels = require('./labels');
|
||||
const protected_session = require('./protected_session');
|
||||
|
||||
async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) {
|
||||
async function createNewNote(parentNoteId, noteOpts, dataKey) {
|
||||
const noteId = utils.newNoteId();
|
||||
const branchId = utils.newBranchId();
|
||||
|
||||
@@ -25,7 +25,7 @@ async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) {
|
||||
await sql.execute('UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0',
|
||||
[parentNoteId, afterNote.notePosition]);
|
||||
|
||||
await sync_table.addNoteReorderingSync(parentNoteId, sourceId);
|
||||
await sync_table.addNoteReorderingSync(parentNoteId);
|
||||
}
|
||||
else {
|
||||
throw new Error('Unknown target: ' + noteOpts.target);
|
||||
@@ -62,7 +62,7 @@ async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) {
|
||||
|
||||
await sql.insert("notes", note);
|
||||
|
||||
await sync_table.addNoteSync(noteId, sourceId);
|
||||
await sync_table.addNoteSync(noteId);
|
||||
|
||||
await sql.insert("branches", {
|
||||
branchId: branchId,
|
||||
@@ -74,7 +74,7 @@ async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) {
|
||||
isDeleted: 0
|
||||
});
|
||||
|
||||
await sync_table.addBranchSync(branchId, sourceId);
|
||||
await sync_table.addBranchSync(branchId);
|
||||
|
||||
return {
|
||||
noteId,
|
||||
@@ -106,7 +106,7 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {})
|
||||
note.mime = "text/html";
|
||||
}
|
||||
|
||||
const {noteId} = await createNewNote(parentNoteId, note, extraOptions.dataKey, extraOptions.sourceId);
|
||||
const {noteId} = await createNewNote(parentNoteId, note, extraOptions.dataKey);
|
||||
|
||||
if (extraOptions.labels) {
|
||||
for (const attrName in extraOptions.labels) {
|
||||
@@ -117,19 +117,19 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {})
|
||||
return noteId;
|
||||
}
|
||||
|
||||
async function protectNoteRecursively(noteId, dataKey, protect, sourceId) {
|
||||
async function protectNoteRecursively(noteId, dataKey, protect) {
|
||||
const note = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);
|
||||
|
||||
await protectNote(note, dataKey, protect, sourceId);
|
||||
await protectNote(note, dataKey, protect);
|
||||
|
||||
const children = await sql.getColumn("SELECT noteId FROM branches WHERE parentNoteId = ? AND isDeleted = 0", [noteId]);
|
||||
|
||||
for (const childNoteId of children) {
|
||||
await protectNoteRecursively(childNoteId, dataKey, protect, sourceId);
|
||||
await protectNoteRecursively(childNoteId, dataKey, protect);
|
||||
}
|
||||
}
|
||||
|
||||
async function protectNote(note, dataKey, protect, sourceId) {
|
||||
async function protectNote(note, dataKey, protect) {
|
||||
let changed = false;
|
||||
|
||||
if (protect && !note.isProtected) {
|
||||
@@ -151,13 +151,13 @@ async function protectNote(note, dataKey, protect, sourceId) {
|
||||
await sql.execute("UPDATE notes SET title = ?, content = ?, isProtected = ? WHERE noteId = ?",
|
||||
[note.title, note.content, note.isProtected, note.noteId]);
|
||||
|
||||
await sync_table.addNoteSync(note.noteId, sourceId);
|
||||
await sync_table.addNoteSync(note.noteId);
|
||||
}
|
||||
|
||||
await protectNoteRevisions(note.noteId, dataKey, protect, sourceId);
|
||||
await protectNoteRevisions(note.noteId, dataKey, protect);
|
||||
}
|
||||
|
||||
async function protectNoteRevisions(noteId, dataKey, protect, sourceId) {
|
||||
async function protectNoteRevisions(noteId, dataKey, protect) {
|
||||
const revisionsToChange = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? AND isProtected != ?", [noteId, protect]);
|
||||
|
||||
for (const revision of revisionsToChange) {
|
||||
@@ -175,11 +175,11 @@ async function protectNoteRevisions(noteId, dataKey, protect, sourceId) {
|
||||
await sql.execute("UPDATE note_revisions SET title = ?, content = ?, isProtected = ? WHERE noteRevisionId = ?",
|
||||
[revision.title, revision.content, revision.isProtected, revision.noteRevisionId]);
|
||||
|
||||
await sync_table.addNoteRevisionSync(revision.noteRevisionId, sourceId);
|
||||
await sync_table.addNoteRevisionSync(revision.noteRevisionId);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveNoteRevision(noteId, dataKey, sourceId, nowStr) {
|
||||
async function saveNoteRevision(noteId, dataKey, nowStr) {
|
||||
const oldNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);
|
||||
|
||||
if (oldNote.type === 'file') {
|
||||
@@ -205,10 +205,10 @@ async function saveNoteRevision(noteId, dataKey, sourceId, nowStr) {
|
||||
dateModifiedTo: nowStr
|
||||
});
|
||||
|
||||
await sync_table.addNoteRevisionSync(newNoteRevisionId, sourceId);
|
||||
await sync_table.addNoteRevisionSync(newNoteRevisionId);
|
||||
}
|
||||
|
||||
async function saveNoteImages(noteId, noteText, sourceId) {
|
||||
async function saveNoteImages(noteId, noteText) {
|
||||
const existingNoteImages = await sql.getRows("SELECT * FROM note_images WHERE noteId = ?", [noteId]);
|
||||
const foundImageIds = [];
|
||||
const now = utils.nowDate();
|
||||
@@ -231,13 +231,13 @@ async function saveNoteImages(noteId, noteText, sourceId) {
|
||||
dateCreated: now
|
||||
});
|
||||
|
||||
await sync_table.addNoteImageSync(noteImageId, sourceId);
|
||||
await sync_table.addNoteImageSync(noteImageId);
|
||||
}
|
||||
else if (existingNoteImage.isDeleted) {
|
||||
await sql.execute("UPDATE note_images SET isDeleted = 0, dateModified = ? WHERE noteImageId = ?",
|
||||
[now, existingNoteImage.noteImageId]);
|
||||
|
||||
await sync_table.addNoteImageSync(existingNoteImage.noteImageId, sourceId);
|
||||
await sync_table.addNoteImageSync(existingNoteImage.noteImageId);
|
||||
}
|
||||
// else we don't need to do anything
|
||||
|
||||
@@ -251,7 +251,7 @@ async function saveNoteImages(noteId, noteText, sourceId) {
|
||||
await sql.execute("UPDATE note_images SET isDeleted = 1, dateModified = ? WHERE noteImageId = ?",
|
||||
[now, unusedNoteImage.noteImageId]);
|
||||
|
||||
await sync_table.addNoteImageSync(unusedNoteImage.noteImageId, sourceId);
|
||||
await sync_table.addNoteImageSync(unusedNoteImage.noteImageId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ async function loadFile(noteId, newNote, dataKey) {
|
||||
newNote.content = oldNote.content;
|
||||
}
|
||||
|
||||
async function updateNote(noteId, newNote, dataKey, sourceId) {
|
||||
async function updateNote(noteId, newNote, dataKey) {
|
||||
if (newNote.type === 'file') {
|
||||
await loadFile(noteId, newNote, dataKey);
|
||||
}
|
||||
@@ -293,10 +293,10 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {
|
||||
&& !existingnoteRevisionId
|
||||
&& msSinceDateCreated >= noteRevisionSnapshotTimeInterval * 1000) {
|
||||
|
||||
await saveNoteRevision(noteId, dataKey, sourceId, nowStr);
|
||||
await saveNoteRevision(noteId, dataKey, nowStr);
|
||||
}
|
||||
|
||||
await saveNoteImages(noteId, newNote.content, sourceId);
|
||||
await saveNoteImages(noteId, newNote.content);
|
||||
|
||||
await protectNoteRevisions(noteId, dataKey, newNote.isProtected);
|
||||
|
||||
@@ -307,11 +307,11 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {
|
||||
nowStr,
|
||||
noteId]);
|
||||
|
||||
await sync_table.addNoteSync(noteId, sourceId);
|
||||
await sync_table.addNoteSync(noteId);
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteNote(branchId, sourceId) {
|
||||
async function deleteNote(branchId) {
|
||||
const branch = await sql.getRowOrNull("SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
|
||||
if (!branch || branch.isDeleted === 1) {
|
||||
@@ -321,7 +321,7 @@ async function deleteNote(branchId, sourceId) {
|
||||
const now = utils.nowDate();
|
||||
|
||||
await sql.execute("UPDATE branches SET isDeleted = 1, dateModified = ? WHERE branchId = ?", [now, branchId]);
|
||||
await sync_table.addBranchSync(branchId, sourceId);
|
||||
await sync_table.addBranchSync(branchId);
|
||||
|
||||
const noteId = await sql.getValue("SELECT noteId FROM branches WHERE branchId = ?", [branchId]);
|
||||
|
||||
@@ -329,12 +329,12 @@ async function deleteNote(branchId, sourceId) {
|
||||
|
||||
if (!notDeletedBranchsCount) {
|
||||
await sql.execute("UPDATE notes SET isDeleted = 1, dateModified = ? WHERE noteId = ?", [now, noteId]);
|
||||
await sync_table.addNoteSync(noteId, sourceId);
|
||||
await sync_table.addNoteSync(noteId);
|
||||
|
||||
const children = await sql.getRows("SELECT branchId FROM branches WHERE parentNoteId = ? AND isDeleted = 0", [noteId]);
|
||||
|
||||
for (const child of children) {
|
||||
await deleteNote(child.branchId, sourceId);
|
||||
await deleteNote(child.branchId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ async function getOption(name) {
|
||||
return row['value'] ? row['value'] : row['opt_value'];
|
||||
}
|
||||
|
||||
async function setOption(name, value, sourceId = null) {
|
||||
async function setOption(name, value) {
|
||||
const opt = await sql.getRow("SELECT * FROM options WHERE name = ?", [name]);
|
||||
|
||||
if (!opt) {
|
||||
@@ -30,14 +30,14 @@ async function setOption(name, value, sourceId = null) {
|
||||
}
|
||||
|
||||
if (opt.isSynced) {
|
||||
await sync_table.addOptionsSync(name, sourceId);
|
||||
await sync_table.addOptionsSync(name);
|
||||
}
|
||||
|
||||
await sql.execute("UPDATE options SET value = ?, dateModified = ? WHERE name = ?",
|
||||
[value, utils.nowDate(), name]);
|
||||
}
|
||||
|
||||
async function createOption(name, value, isSynced, sourceId = null) {
|
||||
async function createOption(name, value, isSynced) {
|
||||
await sql.insert("options", {
|
||||
name: name,
|
||||
value: value,
|
||||
@@ -46,7 +46,7 @@ async function createOption(name, value, isSynced, sourceId = null) {
|
||||
});
|
||||
|
||||
if (isSynced) {
|
||||
await sync_table.addOptionsSync(name, sourceId);
|
||||
await sync_table.addOptionsSync(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ const source_id = require('./source_id');
|
||||
const utils = require('./utils');
|
||||
const sync_setup = require('./sync_setup');
|
||||
const log = require('./log');
|
||||
const cls = require('./cls');
|
||||
|
||||
async function addNoteSync(noteId, sourceId) {
|
||||
await addEntitySync("notes", noteId, sourceId)
|
||||
@@ -49,7 +50,7 @@ async function addEntitySync(entityName, entityId, sourceId) {
|
||||
entityName: entityName,
|
||||
entityId: entityId,
|
||||
syncDate: utils.nowDate(),
|
||||
sourceId: sourceId || source_id.getCurrentSourceId()
|
||||
sourceId: sourceId || cls.getSourceId() || source_id.getCurrentSourceId()
|
||||
});
|
||||
|
||||
if (!sync_setup.isSyncSetup) {
|
||||
|
||||
@@ -76,7 +76,7 @@ async function loadSubTreeNoteIds(parentNoteId, subTreeNoteIds) {
|
||||
}
|
||||
}
|
||||
|
||||
async function sortNotesAlphabetically(parentNoteId, req, sourceId) {
|
||||
async function sortNotesAlphabetically(parentNoteId, req) {
|
||||
await sql.doInTransaction(async () => {
|
||||
const notes = await sql.getRows(`SELECT branchId, noteId, title, isProtected
|
||||
FROM notes JOIN branches USING(noteId)
|
||||
@@ -95,7 +95,7 @@ async function sortNotesAlphabetically(parentNoteId, req, sourceId) {
|
||||
position++;
|
||||
}
|
||||
|
||||
await sync_table.addNoteReorderingSync(parentNoteId, sourceId);
|
||||
await sync_table.addNoteReorderingSync(parentNoteId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user