mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	primitive attribute caching inside note entity, fixes #149
This commit is contained in:
		
							parent
							
								
									ddbd4f73c8
								
							
						
					
					
						commit
						a684879b91
					
				| @ -71,6 +71,18 @@ class Note extends Entity { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async getAttributes() { |     async getAttributes() { | ||||||
|  |         if (!this.__attributeCache) { | ||||||
|  |             await this.loadAttributesToCache(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return this.__attributeCache; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     invalidateAttributeCache() { | ||||||
|  |         this.__attributeCache = null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async loadAttributesToCache() { | ||||||
|         const attributes = await repository.getEntities(` |         const attributes = await repository.getEntities(` | ||||||
|             WITH RECURSIVE |             WITH RECURSIVE | ||||||
|             tree(noteId, level) AS ( |             tree(noteId, level) AS ( | ||||||
| @ -129,7 +141,7 @@ class Note extends Entity { | |||||||
|             attr.isOwned = attr.noteId === this.noteId; |             attr.isOwned = attr.noteId === this.noteId; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return filteredAttributes; |         this.__attributeCache = filteredAttributes; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async hasLabel(name) { |     async hasLabel(name) { | ||||||
| @ -171,6 +183,8 @@ class Note extends Entity { | |||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|             await label.save(); |             await label.save(); | ||||||
|  | 
 | ||||||
|  |             this.invalidateAttributeCache(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -181,6 +195,8 @@ class Note extends Entity { | |||||||
|             if (attribute.type === 'label' && (!value || value === attribute.value)) { |             if (attribute.type === 'label' && (!value || value === attribute.value)) { | ||||||
|                 attribute.isDeleted = true; |                 attribute.isDeleted = true; | ||||||
|                 await attribute.save(); |                 await attribute.save(); | ||||||
|  | 
 | ||||||
|  |                 this.invalidateAttributeCache(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner