mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	note cache fixes, #1805
This commit is contained in:
		
							parent
							
								
									e055d4e15e
								
							
						
					
					
						commit
						da741b522e
					
				@ -31,7 +31,7 @@ function getNotesAndBranchesAndAttributes(noteIds) {
 | 
				
			|||||||
        for (const attr of note.ownedAttributes) {
 | 
					        for (const attr of note.ownedAttributes) {
 | 
				
			||||||
            collectedAttributeIds.add(attr.attributeId);
 | 
					            collectedAttributeIds.add(attr.attributeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (attr.type === 'relation' && attr.name === 'template') {
 | 
					            if (attr.type === 'relation' && attr.name === 'template' && attr.targetNote) {
 | 
				
			||||||
                collectEntityIds(attr.targetNote);
 | 
					                collectEntityIds(attr.targetNote);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -234,11 +234,19 @@ class Note {
 | 
				
			|||||||
        this.ancestorCache = null;
 | 
					        this.ancestorCache = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    invalidateSubtreeCaches() {
 | 
					    invalidateSubtreeCaches(path = []) {
 | 
				
			||||||
 | 
					        if (path.includes(this.noteId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.invalidateThisCache();
 | 
					        this.invalidateThisCache();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (this.children.length || this.targetRelations.length) {
 | 
				
			||||||
 | 
					            path = [...path, this.noteId];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const childNote of this.children) {
 | 
					        for (const childNote of this.children) {
 | 
				
			||||||
            childNote.invalidateSubtreeCaches();
 | 
					            childNote.invalidateSubtreeCaches(path);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const targetRelation of this.targetRelations) {
 | 
					        for (const targetRelation of this.targetRelations) {
 | 
				
			||||||
@ -246,7 +254,7 @@ class Note {
 | 
				
			|||||||
                const note = targetRelation.note;
 | 
					                const note = targetRelation.note;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (note) {
 | 
					                if (note) {
 | 
				
			||||||
                    note.invalidateSubtreeCaches();
 | 
					                    note.invalidateSubtreeCaches(path);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -106,6 +106,8 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
 | 
				
			|||||||
                // first invalidate and only then remove the attribute (otherwise invalidation wouldn't be complete)
 | 
					                // first invalidate and only then remove the attribute (otherwise invalidation wouldn't be complete)
 | 
				
			||||||
                if (attr.isAffectingSubtree || note.isTemplate) {
 | 
					                if (attr.isAffectingSubtree || note.isTemplate) {
 | 
				
			||||||
                    note.invalidateSubtreeCaches();
 | 
					                    note.invalidateSubtreeCaches();
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    note.invalidateThisCache();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                note.ownedAttributes = note.ownedAttributes.filter(attr => attr.attributeId !== attributeId);
 | 
					                note.ownedAttributes = note.ownedAttributes.filter(attr => attr.attributeId !== attributeId);
 | 
				
			||||||
@ -137,7 +139,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
 | 
				
			|||||||
                note.invalidateSubtreeFlatText();
 | 
					                note.invalidateSubtreeFlatText();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
                note.flatTextCache = null;
 | 
					                note.invalidateThisCache();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ class RelationWhereExp extends Expression {
 | 
				
			|||||||
        for (const attr of noteCache.findAttributes('relation', this.relationName)) {
 | 
					        for (const attr of noteCache.findAttributes('relation', this.relationName)) {
 | 
				
			||||||
            const note = attr.note;
 | 
					            const note = attr.note;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (inputNoteSet.hasNoteId(note.noteId)) {
 | 
					            if (inputNoteSet.hasNoteId(note.noteId) && attr.targetNote) {
 | 
				
			||||||
                const subInputNoteSet = new NoteSet([attr.targetNote]);
 | 
					                const subInputNoteSet = new NoteSet([attr.targetNote]);
 | 
				
			||||||
                const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext);
 | 
					                const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user