mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	basic lazy loading of tree now works, still WIP
This commit is contained in:
		| @@ -3,7 +3,26 @@ | ||||
| const sql = require('../../services/sql'); | ||||
| const optionService = require('../../services/options'); | ||||
| const protectedSessionService = require('../../services/protected_session'); | ||||
| const utils = require('../../services/utils'); | ||||
|  | ||||
| async function getNotes(noteIds) { | ||||
|     const questionMarks = noteIds.map(() => "?").join(","); | ||||
|  | ||||
|     const notes = await sql.getRows(` | ||||
|       SELECT noteId, title, isProtected, type, mime | ||||
|       FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); | ||||
|  | ||||
|     protectedSessionService.decryptNotes(notes); | ||||
|  | ||||
|     notes.forEach(note => note.isProtected = !!note.isProtected); | ||||
|     return notes; | ||||
| } | ||||
|  | ||||
| async function getParentToChildren(noteIds) { | ||||
|     const questionMarks = noteIds.map(() => "?").join(","); | ||||
|  | ||||
|     return await sql.getRows(`SELECT branchId, noteId AS 'childNoteId', parentNoteId FROM branches WHERE isDeleted = 0  | ||||
|          AND parentNoteId IN (${questionMarks})`, noteIds); | ||||
| } | ||||
|  | ||||
| async function getTree() { | ||||
|     const branches = await sql.getRows(` | ||||
| @@ -18,34 +37,43 @@ async function getTree() { | ||||
|         SELECT branches.* FROM tree JOIN branches USING(branchId);`); | ||||
|  | ||||
|     const noteIds = branches.map(b => b.noteId); | ||||
|     const questionMarks = branches.map(() => "?").join(","); | ||||
|  | ||||
|     const notes = await sql.getRows(` | ||||
|       SELECT noteId, title, isProtected, type, mime | ||||
|       FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); | ||||
|     const notes = await getNotes(noteIds); | ||||
|  | ||||
|     protectedSessionService.decryptNotes(notes); | ||||
|  | ||||
|     notes.forEach(note => note.isProtected = !!note.isProtected); | ||||
|  | ||||
|     const relationships = await sql.getRows(`SELECT noteId, parentNoteId FROM branches WHERE isDeleted = 0  | ||||
|          AND parentNoteId IN (${questionMarks})`, noteIds); | ||||
|  | ||||
|     const parentToChild = {}; | ||||
|  | ||||
|     for (const rel of relationships) { | ||||
|         parentToChild[rel.parentNoteId] = parentToChild[rel.parentNoteId] || []; | ||||
|         parentToChild[rel.parentNoteId].push(rel.noteId); | ||||
|     } | ||||
|     const parentToChildren = await getParentToChildren(noteIds); | ||||
|  | ||||
|     return { | ||||
|         startNotePath: await optionService.getOption('startNotePath'), | ||||
|         branches: branches, | ||||
|         notes: notes, | ||||
|         parentToChild | ||||
|         branches, | ||||
|         notes, | ||||
|         parentToChildren | ||||
|     }; | ||||
| } | ||||
|  | ||||
| async function load(req) { | ||||
|     let noteIds = req.body.noteIds; | ||||
|     const branchIds = req.body.branchIds; | ||||
|  | ||||
|     if (branchIds && branchIds.length > 0) { | ||||
|         noteIds = await sql.getColumn(`SELECT noteId FROM branches WHERE isDeleted = 0 AND branchId IN(${branchIds.map(() => "?").join(",")})`, branchIds); | ||||
|     } | ||||
|  | ||||
|     const questionMarks = noteIds.map(() => "?").join(","); | ||||
|  | ||||
|     const branches = await sql.getRows(`SELECT * FROM branches WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); | ||||
|  | ||||
|     const notes = await getNotes(noteIds); | ||||
|  | ||||
|     const parentToChildren = await getParentToChildren(noteIds); | ||||
|  | ||||
|     return { | ||||
|         branches, | ||||
|         notes, | ||||
|         parentToChildren | ||||
|     }; | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|     getTree | ||||
|     getTree, | ||||
|     load | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user