mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
consistent checking of is_deleted, some small refactorings
This commit is contained in:
parent
353a9b24c1
commit
07c33979c3
@ -12,7 +12,7 @@ router.put('/:noteTreeId/move-to/:parentNoteId', auth.checkApiAuth, async (req,
|
||||
const parentNoteId = req.params.parentNoteId;
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
const noteToMove = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
|
||||
const noteToMove = await getNoteTree(noteTreeId);
|
||||
|
||||
if (!await validateParentChild(res, parentNoteId, noteToMove.note_id, noteTreeId)) {
|
||||
return;
|
||||
@ -38,8 +38,8 @@ router.put('/:noteTreeId/move-before/:beforeNoteTreeId', auth.checkApiAuth, asyn
|
||||
const beforeNoteTreeId = req.params.beforeNoteTreeId;
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
const noteToMove = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
|
||||
const beforeNote = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [beforeNoteTreeId]);
|
||||
const noteToMove = await getNoteTree(noteTreeId);
|
||||
const beforeNote = await getNoteTree(beforeNoteTreeId);
|
||||
|
||||
if (!await validateParentChild(res, beforeNote.parent_note_id, noteToMove.note_id, noteTreeId)) {
|
||||
return;
|
||||
@ -69,8 +69,8 @@ router.put('/:noteTreeId/move-after/:afterNoteTreeId', auth.checkApiAuth, async
|
||||
const afterNoteTreeId = req.params.afterNoteTreeId;
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
const noteToMove = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
|
||||
const afterNote = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [afterNoteTreeId]);
|
||||
const noteToMove = await getNoteTree(noteTreeId);
|
||||
const afterNote = await getNoteTree(afterNoteTreeId);
|
||||
|
||||
if (!await validateParentChild(res, afterNote.parent_note_id, noteToMove.note_id, noteTreeId)) {
|
||||
return;
|
||||
@ -133,7 +133,7 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, async (re
|
||||
const afterNoteTreeId = req.params.afterNoteTreeId;
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
const afterNote = await sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [afterNoteTreeId]);
|
||||
const afterNote = await getNoteTree(afterNoteTreeId);
|
||||
|
||||
if (!await validateParentChild(res, afterNote.parent_note_id, noteId)) {
|
||||
return;
|
||||
@ -168,13 +168,17 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, async (re
|
||||
async function loadSubTreeNoteIds(parentNoteId, subTreeNoteIds) {
|
||||
subTreeNoteIds.push(parentNoteId);
|
||||
|
||||
const children = await sql.getFirstColumn("SELECT note_id FROM notes_tree WHERE parent_note_id = ?", [parentNoteId]);
|
||||
const children = await sql.getFirstColumn("SELECT note_id FROM notes_tree WHERE parent_note_id = ? AND is_deleted = 0", [parentNoteId]);
|
||||
|
||||
for (const childNoteId of children) {
|
||||
await loadSubTreeNoteIds(childNoteId, subTreeNoteIds);
|
||||
}
|
||||
}
|
||||
|
||||
async function getNoteTree(noteTreeId) {
|
||||
return sql.getFirst("SELECT * FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]);
|
||||
}
|
||||
|
||||
async function validateParentChild(res, parentNoteId, childNoteId, noteTreeId = null) {
|
||||
const existing = await getExistingNoteTree(parentNoteId, childNoteId);
|
||||
|
||||
@ -223,7 +227,7 @@ async function checkTreeCycle(parentNoteId, childNoteId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parentNoteIds = await sql.getFirstColumn("SELECT DISTINCT parent_note_id FROM notes_tree WHERE note_id = ?", [parentNoteId]);
|
||||
const parentNoteIds = await sql.getFirstColumn("SELECT DISTINCT parent_note_id FROM notes_tree WHERE note_id = ? AND is_deleted = 0", [parentNoteId]);
|
||||
|
||||
for (const pid of parentNoteIds) {
|
||||
if (!await checkTreeCycleInner(pid)) {
|
||||
|
@ -112,7 +112,7 @@ router.get('/notes_reordering/:noteTreeParentId', auth.checkApiAuth, async (req,
|
||||
|
||||
res.send({
|
||||
parent_note_id: noteTreeParentId,
|
||||
ordering: await sql.getMap("SELECT note_tree_id, note_position FROM notes_tree WHERE parent_note_id = ?", [noteTreeParentId])
|
||||
ordering: await sql.getMap("SELECT note_tree_id, note_position FROM notes_tree WHERE parent_note_id = ? AND is_deleted = 0", [noteTreeParentId])
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -12,14 +12,20 @@ const notes = require('../../services/notes');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
|
||||
router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
||||
const notes = await sql.getAll("SELECT "
|
||||
+ "notes_tree.*, "
|
||||
+ "notes.note_title, "
|
||||
+ "notes.is_protected "
|
||||
+ "FROM notes_tree "
|
||||
+ "JOIN notes ON notes.note_id = notes_tree.note_id "
|
||||
+ "WHERE notes.is_deleted = 0 AND notes_tree.is_deleted = 0 "
|
||||
+ "ORDER BY note_position");
|
||||
const notes = await sql.getAll(`
|
||||
SELECT
|
||||
notes_tree.*,
|
||||
notes.note_title,
|
||||
notes.is_protected
|
||||
FROM
|
||||
notes_tree
|
||||
JOIN
|
||||
notes ON notes.note_id = notes_tree.note_id
|
||||
WHERE
|
||||
notes.is_deleted = 0
|
||||
AND notes_tree.is_deleted = 0
|
||||
ORDER BY
|
||||
note_position`);
|
||||
|
||||
const dataKey = protected_session.getDataKey(req);
|
||||
|
||||
|
@ -19,7 +19,7 @@ async function runCheck(query, errorText, errorList) {
|
||||
|
||||
async function checkTreeCycles(errorList) {
|
||||
const childToParents = {};
|
||||
const rows = await sql.getAll("SELECT note_id, parent_note_id FROM notes_tree");
|
||||
const rows = await sql.getAll("SELECT note_id, parent_note_id FROM notes_tree WHERE is_deleted = 0");
|
||||
|
||||
for (const row of rows) {
|
||||
const childNoteId = row.note_id;
|
||||
|
@ -74,7 +74,7 @@ async function protectNoteRecursively(noteId, dataKey, protect, sourceId) {
|
||||
|
||||
await protectNote(note, dataKey, protect, sourceId);
|
||||
|
||||
const children = await sql.getFirstColumn("SELECT note_id FROM notes_tree WHERE parent_note_id = ?", [noteId]);
|
||||
const children = await sql.getFirstColumn("SELECT note_id FROM notes_tree WHERE parent_note_id = ? AND is_deleted = 0", [noteId]);
|
||||
|
||||
for (const childNoteId of children) {
|
||||
await protectNoteRecursively(childNoteId, dataKey, protect, sourceId);
|
||||
|
@ -37,9 +37,9 @@ const dbReady = new Promise((resolve, reject) => {
|
||||
await executeScript(notesSql);
|
||||
await executeScript(notesTreeSql);
|
||||
|
||||
const noteId = await getFirstValue("SELECT note_id FROM notes_tree WHERE parent_note_id = 'root' ORDER BY note_position");
|
||||
const startNoteId = await getFirstValue("SELECT note_id FROM notes_tree WHERE parent_note_id = 'root' AND is_deleted = 0 ORDER BY note_position");
|
||||
|
||||
await require('./options').initOptions(noteId);
|
||||
await require('./options').initOptions(startNoteId);
|
||||
await require('./sync_table').fillAllSyncRows();
|
||||
});
|
||||
|
||||
|
@ -214,7 +214,7 @@ async function pushEntity(sync, syncContext) {
|
||||
else if (sync.entity_name === 'notes_reordering') {
|
||||
entity = {
|
||||
parent_note_id: sync.entity_id,
|
||||
ordering: await sql.getMap('SELECT note_tree_id, note_position FROM notes_tree WHERE parent_note_id = ?', [sync.entity_id])
|
||||
ordering: await sql.getMap('SELECT note_tree_id, note_position FROM notes_tree WHERE parent_note_id = ? AND is_deleted = 0', [sync.entity_id])
|
||||
};
|
||||
}
|
||||
else if (sync.entity_name === 'options') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user