mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	optimization of search
This commit is contained in:
		
							parent
							
								
									5a8c3f6a2b
								
							
						
					
					
						commit
						172f3689fa
					
				@ -152,6 +152,12 @@ function getSomePath(note, path = []) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function getNotePath(noteId) {
 | 
					function getNotePath(noteId) {
 | 
				
			||||||
    const note = noteCache.notes[noteId];
 | 
					    const note = noteCache.notes[noteId];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!note) {
 | 
				
			||||||
 | 
					        console.trace(`Cannot find note ${noteId} in cache.`);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const retPath = getSomePath(note);
 | 
					    const retPath = getSomePath(note);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (retPath) {
 | 
					    if (retPath) {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ class NoteSet {
 | 
				
			|||||||
    constructor(notes = []) {
 | 
					    constructor(notes = []) {
 | 
				
			||||||
        /** @type {Note[]} */
 | 
					        /** @type {Note[]} */
 | 
				
			||||||
        this.notes = notes;
 | 
					        this.notes = notes;
 | 
				
			||||||
 | 
					        this.noteIdSet = new Set(notes.map(note => note.noteId));
 | 
				
			||||||
        /** @type {boolean} */
 | 
					        /** @type {boolean} */
 | 
				
			||||||
        this.sorted = false;
 | 
					        this.sorted = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -11,6 +12,7 @@ class NoteSet {
 | 
				
			|||||||
    add(note) {
 | 
					    add(note) {
 | 
				
			||||||
        if (!this.hasNote(note)) {
 | 
					        if (!this.hasNote(note)) {
 | 
				
			||||||
            this.notes.push(note);
 | 
					            this.notes.push(note);
 | 
				
			||||||
 | 
					            this.noteIdSet.add(note.noteId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -25,12 +27,12 @@ class NoteSet {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hasNoteId(noteId) {
 | 
					    hasNoteId(noteId) {
 | 
				
			||||||
        // TODO: optimize
 | 
					        return this.noteIdSet.has(noteId);
 | 
				
			||||||
        return !!this.notes.find(note => note.noteId === noteId);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mergeIn(anotherNoteSet) {
 | 
					    mergeIn(anotherNoteSet) {
 | 
				
			||||||
        this.notes = this.notes.concat(anotherNoteSet.notes);
 | 
					        this.notes = this.notes.concat(anotherNoteSet.notes);
 | 
				
			||||||
 | 
					        this.noteIdSet = new Set(this.notes.map(note => note.noteId));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    minus(anotherNoteSet) {
 | 
					    minus(anotherNoteSet) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user