note cache fixes, #1805

This commit is contained in:
zadam 2021-03-30 21:39:42 +02:00
parent e055d4e15e
commit da741b522e
4 changed files with 16 additions and 6 deletions

View file

@ -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);
} }
} }

View file

@ -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);
} }
} }
} }

View file

@ -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 {

View file

@ -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);