Skip to content

Build your personal knowledge base with Trilium Notes

new note cache WIP

zadam552fc5261aab
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 70caa7f2a0..fa5ae48bf6 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
diff --git a/src/services/note_cache.js b/src/services/note_cache.js
index 4285eccd9e..de4ee09f06 100644
--- a/src/services/note_cache.js
+++ b/src/services/note_cache.js
@@ -7,14 +7,14 @@ const utils = require('./utils');
const hoistedNoteService = require('./hoisted_note');
const stringSimilarity = require('string-similarity');
-/** @var {Object.<String, Note>} */
+/** @type {Object.<String, Note>} */
let notes;
-/** @var {Object.<String, Branch>} */
+/** @type {Object.<String, Branch>} */
let branches
-/** @var {Object.<String, Attribute>} */
+/** @type {Object.<String, Attribute>} */
let attributes;
-/** @var {Object.<String, Attribute[]>} */
+/** @type {Object.<String, Attribute[]>} */
let noteAttributeCache = {};
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 loadedPromiseResolve;
/** 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`,
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`,
row => new Branch(row));
attributes = await getMappedRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`,
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) {
const childNote = notes[branch.noteId];
@@ -654,4 +722,4 @@ module.exports = {
isInAncestor,
load,
findSimilarNotes
-};
\ No newline at end of file
+};