mirror of
https://github.com/zadam/trilium.git
synced 2025-02-22 22:13:07 +08:00
new note cache WIP
This commit is contained in:
parent
83c9e6e846
commit
552fc5261a
2 changed files with 74 additions and 6 deletions
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue