mirror of
https://github.com/zadam/trilium.git
synced 2026-01-24 08:09:12 +01:00
note cache fixes after refactoring
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const noteCache = require('../note_cache');
|
||||
|
||||
class Attribute {
|
||||
constructor(row) {
|
||||
constructor(noteCache, row) {
|
||||
/** @param {NoteCache} */
|
||||
this.noteCache = noteCache;
|
||||
/** @param {string} */
|
||||
this.attributeId = row.attributeId;
|
||||
/** @param {string} */
|
||||
@@ -17,11 +17,11 @@ class Attribute {
|
||||
/** @param {boolean} */
|
||||
this.isInheritable = !!row.isInheritable;
|
||||
|
||||
noteCache.notes[this.noteId].ownedAttributes.push(this);
|
||||
this.noteCache.notes[this.noteId].ownedAttributes.push(this);
|
||||
|
||||
const key = `${this.type-this.name}`;
|
||||
noteCache.attributeIndex[key] = noteCache.attributeIndex[key] || [];
|
||||
noteCache.attributeIndex[key].push(this);
|
||||
this.noteCache.attributeIndex[key] = this.noteCache.attributeIndex[key] || [];
|
||||
this.noteCache.attributeIndex[key].push(this);
|
||||
|
||||
const targetNote = this.targetNote;
|
||||
|
||||
@@ -36,12 +36,12 @@ class Attribute {
|
||||
}
|
||||
|
||||
get note() {
|
||||
return noteCache.notes[this.noteId];
|
||||
return this.noteCache.notes[this.noteId];
|
||||
}
|
||||
|
||||
get targetNote() {
|
||||
if (this.type === 'relation') {
|
||||
return noteCache.notes[this.value];
|
||||
return this.noteCache.notes[this.value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const noteCache = require('../note_cache');
|
||||
|
||||
class Branch {
|
||||
constructor(row) {
|
||||
constructor(noteCache, row) {
|
||||
/** @param {NoteCache} */
|
||||
this.noteCache = noteCache;
|
||||
/** @param {string} */
|
||||
this.branchId = row.branchId;
|
||||
/** @param {string} */
|
||||
@@ -17,7 +17,7 @@ class Branch {
|
||||
return;
|
||||
}
|
||||
|
||||
const childNote = noteCache.notes[this.noteId];
|
||||
const childNote = this.noteCache.notes[this.noteId];
|
||||
const parentNote = this.parentNote;
|
||||
|
||||
if (!childNote) {
|
||||
@@ -30,12 +30,12 @@ class Branch {
|
||||
|
||||
parentNote.children.push(childNote);
|
||||
|
||||
noteCache.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
|
||||
this.noteCache.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
|
||||
}
|
||||
|
||||
/** @return {Note} */
|
||||
get parentNote() {
|
||||
const note = noteCache.notes[this.parentNoteId];
|
||||
const note = this.noteCache.notes[this.parentNoteId];
|
||||
|
||||
if (!note) {
|
||||
console.log(`Cannot find note ${this.parentNoteId}`);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
const noteCache = require('../note_cache');
|
||||
const protectedSessionService = require('../../protected_session');
|
||||
|
||||
class Note {
|
||||
constructor(row) {
|
||||
constructor(noteCache, row) {
|
||||
/** @param {NoteCache} */
|
||||
this.noteCache = noteCache;
|
||||
/** @param {string} */
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} */
|
||||
@@ -33,7 +36,7 @@ class Note {
|
||||
this.flatTextCache = null;
|
||||
|
||||
if (protectedSessionService.isProtectedSessionAvailable()) {
|
||||
noteCache.decryptProtectedNote(this);
|
||||
this.decrypt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +55,7 @@ class Note {
|
||||
|
||||
for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates
|
||||
if (ownedAttr.type === 'relation' && ownedAttr.name === 'template') {
|
||||
const templateNote = notes[ownedAttr.value];
|
||||
const templateNote = this.noteCache.notes[ownedAttr.value];
|
||||
|
||||
if (templateNote) {
|
||||
templateAttributes.push(...templateNote.attributes);
|
||||
|
||||
@@ -33,15 +33,15 @@ class NoteCache {
|
||||
await sqlInit.dbReady;
|
||||
|
||||
this.notes = await this.getMappedRows(`SELECT noteId, title, isProtected FROM notes WHERE isDeleted = 0`,
|
||||
row => new Note(row));
|
||||
row => new Note(this, row));
|
||||
|
||||
this.branches = await this.getMappedRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`,
|
||||
row => new Branch(row));
|
||||
row => new Branch(this, row));
|
||||
|
||||
this.attributeIndex = [];
|
||||
|
||||
this.attributes = await this.getMappedRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`,
|
||||
row => new Attribute(row));
|
||||
row => new Attribute(this, row));
|
||||
|
||||
this.loaded = true;
|
||||
}
|
||||
@@ -94,13 +94,13 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
|
||||
note.isDecrypted = !entity.isProtected || !!entity.isContentAvailable;
|
||||
note.flatTextCache = null;
|
||||
|
||||
noteCache.decryptProtectedNote(note);
|
||||
note.decrypt();
|
||||
}
|
||||
else {
|
||||
const note = new Note(entity);
|
||||
noteCache.notes[noteId] = note;
|
||||
|
||||
noteCache.decryptProtectedNote(note);
|
||||
note.decrypt();
|
||||
}
|
||||
}
|
||||
else if (entityName === 'branches') {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const noteCache = require('./note_cache');
|
||||
const hoistedNoteService = require('../hoisted_note');
|
||||
const stringSimilarity = require('string-similarity');
|
||||
|
||||
function isNotePathArchived(notePath) {
|
||||
const noteId = notePath[notePath.length - 1];
|
||||
@@ -69,7 +70,7 @@ function getNoteTitle(childNoteId, parentNoteId) {
|
||||
title = childNote.title;
|
||||
}
|
||||
|
||||
const branch = parentNote ? getBranch(childNote.noteId, parentNote.noteId) : null;
|
||||
const branch = parentNote ? noteCache.getBranch(childNote.noteId, parentNote.noteId) : null;
|
||||
|
||||
return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title;
|
||||
}
|
||||
@@ -199,7 +200,7 @@ async function findSimilarNotes(noteId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
for (const note of Object.values(notes)) {
|
||||
for (const note of Object.values(noteCache.notes)) {
|
||||
if (note.isProtected && !note.isDecrypted) {
|
||||
continue;
|
||||
}
|
||||
@@ -229,7 +230,9 @@ function isAvailable(noteId) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSomePath,
|
||||
getNotePath,
|
||||
getNoteTitle,
|
||||
getNoteTitleForPath,
|
||||
isAvailable,
|
||||
isArchived,
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
class NoteSet {
|
||||
constructor(notes = []) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
add(note) {
|
||||
this.notes.push(note);
|
||||
}
|
||||
|
||||
addAll(notes) {
|
||||
this.notes.push(...notes);
|
||||
}
|
||||
|
||||
hasNoteId(noteId) {
|
||||
// TODO: optimize
|
||||
return !!this.notes.find(note => note.noteId === noteId);
|
||||
}
|
||||
|
||||
mergeIn(anotherNoteSet) {
|
||||
this.notes = this.notes.concat(anotherNoteSet.arr);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteSet;
|
||||
Reference in New Issue
Block a user