Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
converted NoteRevision entity to the becca
zadame466c393eb80
diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.jsindex 88fd5d5904..00ed717094 100644--- a/src/routes/api/note_revisions.js+++ b/src/routes/api/note_revisions.js@@ -7,6 +7,7 @@ const noteRevisionService = require('../../services/note_revisions');const utils = require('../../services/utils');const sql = require('../../services/sql');const path = require('path');+const becca = require("../../services/becca/becca.js");function getNoteRevisions(req) {return repository.getEntities(`@@ -19,11 +20,11 @@ function getNoteRevisions(req) {}function getNoteRevision(req) {- const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);+ const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);if (noteRevision.type === 'file') {if (noteRevision.isStringNote()) {- noteRevision.content = (noteRevision.getContent()).substr(0, 10000);+ noteRevision.content = noteRevision.getContent().substr(0, 10000);}}else {@@ -62,7 +63,7 @@ function getRevisionFilename(noteRevision) {}function downloadNoteRevision(req, res) {- const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);+ const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);if (noteRevision.noteId !== req.params.noteId) {return res.status(400).send(`Note revision ${req.params.noteRevisionId} does not belong to note ${req.params.noteId}`);@@ -92,7 +93,7 @@ function eraseNoteRevision(req) {}function restoreNoteRevision(req) {- const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);+ const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);if (noteRevision) {const note = noteRevision.getNote();diff --git a/src/routes/api/tree.js b/src/routes/api/tree.jsindex 371faae187..49bb8bf37d 100644--- a/src/routes/api/tree.js+++ b/src/routes/api/tree.js@@ -23,7 +23,7 @@ function getNotesAndBranchesAndAttributes(noteIds) {}for (const childNote of note.children) {- const childBranch = becca.getBranch(childNote.noteId, note.noteId);+ const childBranch = becca.getBranchFromChildAndParent(childNote.noteId, note.noteId);collectedBranchIds.add(childBranch.branchId);}@@ -127,7 +127,7 @@ function getTree(req) {for (const childNote of parentNote.children) {collectedNoteIds.add(childNote.noteId);- const childBranch = becca.getBranch(childNote.noteId, parentNote.noteId);+ const childBranch = becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId);if (childBranch.isExpanded) {collect(childBranch.childNote);diff --git a/src/services/becca/becca.js b/src/services/becca/becca.jsindex 27662ed958..8118a72524 100644--- a/src/services/becca/becca.js+++ b/src/services/becca/becca.js@@ -1,5 +1,8 @@"use strict";+const sql = require("../sql.js");+const NoteRevision = require("./entities/note_revision.js");+class Becca {constructor() {this.reset();@@ -45,9 +48,27 @@ class Becca {}}- getBranch(childNoteId, parentNoteId) {+ getNote(noteId) {+ return this.notes[noteId];+ }++ getBranch(branchId) {+ return this.branches[branchId];+ }++ getAttribute(attributeId) {+ return this.attributes[attributeId];+ }++ getBranchFromChildAndParent(childNoteId, parentNoteId) {return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];}++ getNoteRevision(noteRevisionId) {+ const row = sql.getRow("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [noteRevisionId]);++ return row ? new NoteRevision(row) : null;+ }}const becca = new Becca();diff --git a/src/services/becca/becca_service.js b/src/services/becca/becca_service.jsindex 2a36fb6722..65d29af095 100644--- a/src/services/becca/becca_service.js+++ b/src/services/becca/becca_service.js@@ -80,7 +80,7 @@ function getNoteTitle(childNoteId, parentNoteId) {title = childNote.title;}- const branch = parentNote ? becca.getBranch(childNote.noteId, parentNote.noteId) : null;+ const branch = parentNote ? becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId) : null;return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title;}@@ -175,7 +175,7 @@ function getNotePath(noteId) {return {noteId: noteId,- branchId: becca.getBranch(noteId, parentNote.noteId).branchId,+ branchId: becca.getBranchFromChildAndParent(noteId, parentNote.noteId).branchId,title: noteTitle,notePath: retPath,path: retPath.join('/')diff --git a/src/services/becca/entities/note.js b/src/services/becca/entities/note.jsindex dc251dd72b..ff5b475589 100644--- a/src/services/becca/entities/note.js+++ b/src/services/becca/entities/note.js@@ -107,7 +107,7 @@ class Note extends AbstractEntity {}getChildBranches() {- return this.children.map(childNote => this.becca.getBranch(childNote.noteId, this.noteId));+ return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId));}/*