mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	new note cache WIP
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/dataSources.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/dataSources.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <project version="4"> | <project version="4"> | ||||||
|   <component name="DataSourceManagerImpl" format="xml" multifile-model="true"> |   <component name="DataSourceManagerImpl" format="xml" multifile-model="true"> | ||||||
|     <data-source source="LOCAL" name="SQLite - document.db" uuid="d0fd879f-1e1d-4d5c-9c21-0e5cf9ab2976"> |     <data-source source="LOCAL" name="document.db" uuid="4e69c96a-8a2b-43f5-9b40-d1608f75f7a4"> | ||||||
|       <driver-ref>sqlite.xerial</driver-ref> |       <driver-ref>sqlite.xerial</driver-ref> | ||||||
|       <synchronize>true</synchronize> |       <synchronize>true</synchronize> | ||||||
|       <jdbc-driver>org.sqlite.JDBC</jdbc-driver> |       <jdbc-driver>org.sqlite.JDBC</jdbc-driver> | ||||||
|   | |||||||
| @@ -7,14 +7,14 @@ const utils = require('./utils'); | |||||||
| const hoistedNoteService = require('./hoisted_note'); | const hoistedNoteService = require('./hoisted_note'); | ||||||
| const stringSimilarity = require('string-similarity'); | const stringSimilarity = require('string-similarity'); | ||||||
|  |  | ||||||
| /** @var {Object.<String, Note>} */ | /** @type {Object.<String, Note>} */ | ||||||
| let notes; | let notes; | ||||||
| /** @var {Object.<String, Branch>} */ | /** @type {Object.<String, Branch>} */ | ||||||
| let branches | let branches | ||||||
| /** @var {Object.<String, Attribute>} */ | /** @type {Object.<String, Attribute>} */ | ||||||
| let attributes; | let attributes; | ||||||
|  |  | ||||||
| /** @var {Object.<String, Attribute[]>} */ | /** @type {Object.<String, Attribute[]>} */ | ||||||
| let noteAttributeCache = {}; | let noteAttributeCache = {}; | ||||||
|  |  | ||||||
| let childParentToBranch = {}; | let childParentToBranch = {}; | ||||||
| @@ -109,6 +109,59 @@ class Attribute { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | class FulltextReference { | ||||||
|  |     /** | ||||||
|  |      * @param type - attributeName, attributeValue, title | ||||||
|  |      * @param id - attributeId, noteId | ||||||
|  |      */ | ||||||
|  |     constructor(type, id) { | ||||||
|  |         this.type = type; | ||||||
|  |         this.id = id; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** @type {Object.<String, FulltextReference>} */ | ||||||
|  | let fulltext = {}; | ||||||
|  |  | ||||||
|  | /** @type {Object.<String, AttributeMeta>} */ | ||||||
|  | let attributeMetas = {}; | ||||||
|  |  | ||||||
|  | class AttributeMeta { | ||||||
|  |     constructor(attribute) { | ||||||
|  |         this.type = attribute.type; | ||||||
|  |         this.name = attribute.name; | ||||||
|  |         this.isInheritable = attribute.isInheritable; | ||||||
|  |         this.attributeIds = new Set(attribute.attributeId); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     addAttribute(attribute) { | ||||||
|  |         this.attributeIds.add(attribute.attributeId); | ||||||
|  |         this.isInheritable = this.isInheritable || attribute.isInheritable; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     updateAttribute(attribute) { | ||||||
|  |         if (attribute.isDeleted) { | ||||||
|  |             this.attributeIds.delete(attribute.attributeId); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             this.attributeIds.add(attribute.attributeId); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         this.isInheritable = !!this.attributeIds.find(attributeId => attributes[attributeId].isInheritable); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function addToAttributeMeta(attribute) { | ||||||
|  |     const key = `${attribute.type}-${attribute.name}`; | ||||||
|  |  | ||||||
|  |     if (!(key in attributeMetas)) { | ||||||
|  |         attributeMetas[key] = new AttributeMeta(attribute); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         attributeMetas[key].addAttribute(attribute); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| let loaded = false; | let loaded = false; | ||||||
| let loadedPromiseResolve; | let loadedPromiseResolve; | ||||||
| /** Is resolved after the initial load */ | /** Is resolved after the initial load */ | ||||||
| @@ -140,12 +193,27 @@ async function load() { | |||||||
|     notes = await getMappedRows(`SELECT noteId, title, isProtected FROM notes WHERE isDeleted = 0`, |     notes = await getMappedRows(`SELECT noteId, title, isProtected FROM notes WHERE isDeleted = 0`, | ||||||
|         row => new Note(row)); |         row => new Note(row)); | ||||||
|  |  | ||||||
|  |     for (const note of notes) { | ||||||
|  |         fulltext[note.title] = fulltext[note.title] || []; | ||||||
|  |         fulltext[note.title].push(new FulltextReference('note', note.noteId)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     branches = await getMappedRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`, |     branches = await getMappedRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`, | ||||||
|         row => new Branch(row)); |         row => new Branch(row)); | ||||||
|  |  | ||||||
|     attributes = await getMappedRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`, |     attributes = await getMappedRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`, | ||||||
|         row => new Attribute(row)); |         row => new Attribute(row)); | ||||||
|  |  | ||||||
|  |     for (const attr of attributes) { | ||||||
|  |         addToAttributeMeta(attributes); | ||||||
|  |  | ||||||
|  |         fulltext[attr.name] = fulltext[attr.name] || []; | ||||||
|  |         fulltext[attr.name].push(new FulltextReference('aName', attr.attributeId)); | ||||||
|  |  | ||||||
|  |         fulltext[attr.value] = fulltext[attr.value] || []; | ||||||
|  |         fulltext[attr.value].push(new FulltextReference('aVal', attr.attributeId)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     for (const branch of branches) { |     for (const branch of branches) { | ||||||
|         const childNote = notes[branch.noteId]; |         const childNote = notes[branch.noteId]; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user