hoisting notes WIP

This commit is contained in:
azivner
2018-12-11 21:53:56 +01:00
parent 8171b68b18
commit 6fbf28b30d
8 changed files with 67 additions and 6 deletions

View File

@@ -50,18 +50,20 @@ async function getRelations(noteIds) {
}
async function getTree() {
const hoistedNoteId = await optionService.getOption('hoistedNoteId');
// we fetch all branches of notes, even if that particular branch isn't visible
// this allows us to e.g. detect and properly display clones
const branches = await sql.getRows(`
WITH RECURSIVE
tree(branchId, noteId, isExpanded) AS (
SELECT branchId, noteId, isExpanded FROM branches WHERE branchId = 'root'
SELECT branchId, noteId, isExpanded FROM branches WHERE noteId = ?
UNION ALL
SELECT branches.branchId, branches.noteId, branches.isExpanded FROM branches
JOIN tree ON branches.parentNoteId = tree.noteId
WHERE tree.isExpanded = 1 AND branches.isDeleted = 0
)
SELECT branches.* FROM tree JOIN branches USING(noteId) WHERE branches.isDeleted = 0 ORDER BY branches.notePosition`);
SELECT branches.* FROM tree JOIN branches USING(noteId) WHERE branches.isDeleted = 0 ORDER BY branches.notePosition`, [hoistedNoteId]);
const noteIds = Array.from(new Set(branches.map(b => b.noteId)));