From af5b1021c7ce68839009c969c071e2ba64ab8cc2 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 16 Apr 2021 22:57:37 +0200 Subject: [PATCH] renamed treeCache into froca --- docs/backend_api/entities_note.js.html | 2 +- docs/frontend_api/NoteShort.html | 10 ++-- docs/frontend_api/branch.js.html | 6 +-- docs/frontend_api/entities_attribute.js.html | 8 ++-- docs/frontend_api/entities_branch.js.html | 10 ++-- docs/frontend_api/entities_note_full.js.html | 4 +- docs/frontend_api/entities_note_short.js.html | 44 ++++++++--------- docs/frontend_api/note_full.js.html | 4 +- docs/frontend_api/note_short.js.html | 34 ++++++------- .../services_frontend_script_api.js.html | 8 ++-- src/entities/note.js | 2 +- src/public/app/dialogs/branch_prefix.js | 8 ++-- src/public/app/dialogs/clone_to.js | 10 ++-- src/public/app/dialogs/delete_notes.js | 6 +-- src/public/app/dialogs/export.js | 4 +- src/public/app/dialogs/include_note.js | 4 +- src/public/app/dialogs/move_to.js | 10 ++-- src/public/app/dialogs/recent_changes.js | 8 ++-- src/public/app/entities/attribute.js | 8 ++-- src/public/app/entities/branch.js | 10 ++-- src/public/app/entities/note_short.js | 46 +++++++++--------- src/public/app/services/app_context.js | 4 +- src/public/app/services/attribute_renderer.js | 4 +- src/public/app/services/branches.js | 10 ++-- src/public/app/services/bundle.js | 4 +- src/public/app/services/clipboard.js | 8 ++-- src/public/app/services/date_notes.js | 14 +++--- .../app/services/frontend_script_api.js | 8 ++-- src/public/app/services/glob.js | 4 +- src/public/app/services/link.js | 4 +- src/public/app/services/link_map.js | 8 ++-- src/public/app/services/load_results.js | 8 ++-- src/public/app/services/note_autocomplete.js | 4 +- .../app/services/note_content_renderer.js | 4 +- src/public/app/services/note_create.js | 8 ++-- src/public/app/services/note_list_renderer.js | 4 +- src/public/app/services/note_tooltip.js | 4 +- src/public/app/services/protected_session.js | 10 ++-- src/public/app/services/script_context.js | 8 ++-- src/public/app/services/search.js | 4 +- src/public/app/services/tab_context.js | 14 +++--- src/public/app/services/tab_manager.js | 6 +-- src/public/app/services/tree.js | 14 +++--- src/public/app/services/tree_cache.js | 16 +++---- src/public/app/services/tree_context_menu.js | 8 ++-- src/public/app/services/ws.js | 38 +++++++-------- .../attribute_widgets/attribute_detail.js | 6 +-- .../attribute_widgets/attribute_editor.js | 4 +- .../collapsible_widgets/edited_notes.js | 4 +- .../widgets/collapsible_widgets/link_map.js | 4 +- src/public/app/widgets/note_tree.js | 48 +++++++++---------- src/public/app/widgets/quick_search.js | 4 +- src/public/app/widgets/similar_notes.js | 6 +-- src/public/app/widgets/tab_aware_widget.js | 2 +- src/public/app/widgets/tab_row.js | 6 +-- .../search_definition.js | 4 +- .../type_widgets/abstract_text_type_widget.js | 4 +- .../app/widgets/type_widgets/editable_text.js | 6 +-- .../widgets/type_widgets/read_only_text.js | 4 +- .../app/widgets/type_widgets/relation_map.js | 4 +- src/services/note_cache/entities/note.js | 6 +-- src/services/note_cache/note_cache_loader.js | 6 +-- src/services/script.js | 2 +- 63 files changed, 292 insertions(+), 292 deletions(-) diff --git a/docs/backend_api/entities_note.js.html b/docs/backend_api/entities_note.js.html index ab5ec0443..20366f2d3 100644 --- a/docs/backend_api/entities_note.js.html +++ b/docs/backend_api/entities_note.js.html @@ -411,7 +411,7 @@ class Note extends Entity { return false; } - // FIXME: this code is quite questionable, one problem is that other caches (TreeCache, NoteCache) have nothing like that + // FIXME: this code is quite questionable, one problem is that other caches (Froca, NoteCache) have nothing like that if (attr.isDefinition()) { const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); diff --git a/docs/frontend_api/NoteShort.html b/docs/frontend_api/NoteShort.html index 72ad5005e..00d441ae3 100644 --- a/docs/frontend_api/NoteShort.html +++ b/docs/frontend_api/NoteShort.html @@ -28,11 +28,11 @@
-

NoteShort(treeCache, row)

+

NoteShort(froca, row)

FIXME: since there's no "full note" anymore we can rename this to Note -This note's representation is used in note tree and is kept in TreeCache.
+This note's representation is used in note tree and is kept in Froca.
@@ -47,7 +47,7 @@ This note's representation is used in note tree and is kept in TreeCache. -

new NoteShort(treeCache, row)

+

new NoteShort(froca, row)

@@ -87,13 +87,13 @@ This note's representation is used in note tree and is kept in TreeCache. - treeCache + froca -TreeCache +Froca diff --git a/docs/frontend_api/branch.js.html b/docs/frontend_api/branch.js.html index 9c70609a7..0fbbe0806 100644 --- a/docs/frontend_api/branch.js.html +++ b/docs/frontend_api/branch.js.html @@ -28,8 +28,8 @@
/** Represents mapping between note and parent note */
 class Branch {
-    constructor(treeCache, row) {
-        this.treeCache = treeCache;
+    constructor(froca, row) {
+        this.froca = froca;
         /** @param {string} primary key */
         this.branchId = row.branchId;
         /** @param {string} */
@@ -47,7 +47,7 @@ class Branch {
 
     /** @returns {NoteShort} */
     async getNote() {
-        return await this.treeCache.getNote(this.noteId);
+        return await this.froca.getNote(this.noteId);
     }
 
     /** @returns {boolean} true if it's top level, meaning its parent is root note */
diff --git a/docs/frontend_api/entities_attribute.js.html b/docs/frontend_api/entities_attribute.js.html
index c25dca612..59872f59b 100644
--- a/docs/frontend_api/entities_attribute.js.html
+++ b/docs/frontend_api/entities_attribute.js.html
@@ -29,8 +29,8 @@
             
import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
 
 class Attribute {
-    constructor(treeCache, row) {
-        this.treeCache = treeCache;
+    constructor(froca, row) {
+        this.froca = froca;
 
         this.update(row);
     }
@@ -56,7 +56,7 @@ class Attribute {
 
     /** @returns {NoteShort} */
     getNote() {
-        return this.treeCache.notes[this.noteId];
+        return this.froca.notes[this.noteId];
     }
 
     get targetNoteId() { // alias
@@ -123,7 +123,7 @@ class Attribute {
 
     get dto() {
         const dto = Object.assign({}, this);
-        delete dto.treeCache;
+        delete dto.froca;
 
         return dto;
     }
diff --git a/docs/frontend_api/entities_branch.js.html b/docs/frontend_api/entities_branch.js.html
index 1e84430ea..129c2c2d6 100644
--- a/docs/frontend_api/entities_branch.js.html
+++ b/docs/frontend_api/entities_branch.js.html
@@ -28,8 +28,8 @@
         
/** Represents mapping between note and parent note */
 class Branch {
-    constructor(treeCache, row) {
-        this.treeCache = treeCache;
+    constructor(froca, row) {
+        this.froca = froca;
 
         this.update(row);
     }
@@ -55,17 +55,17 @@ class Branch {
 
     /** @returns {NoteShort} */
     async getNote() {
-        return this.treeCache.getNote(this.noteId);
+        return this.froca.getNote(this.noteId);
     }
 
     /** @returns {NoteShort} */
     getNoteFromCache() {
-        return this.treeCache.getNoteFromCache(this.noteId);
+        return this.froca.getNoteFromCache(this.noteId);
     }
 
     /** @returns {NoteShort} */
     async getParentNote() {
-        return this.treeCache.getNote(this.parentNoteId);
+        return this.froca.getNote(this.parentNoteId);
     }
 
     /** @returns {boolean} true if it's top level, meaning its parent is root note */
diff --git a/docs/frontend_api/entities_note_full.js.html b/docs/frontend_api/entities_note_full.js.html
index b66927b7b..64503a4e4 100644
--- a/docs/frontend_api/entities_note_full.js.html
+++ b/docs/frontend_api/entities_note_full.js.html
@@ -32,8 +32,8 @@
  * Represents full note, specifically including note's content.
  */
 class NoteFull extends NoteShort {
-    constructor(treeCache, row, noteShort) {
-        super(treeCache, row, []);
+    constructor(froca, row, noteShort) {
+        super(froca, row, []);
 
         /** @param {string} */
         this.content = row.content;
diff --git a/docs/frontend_api/entities_note_short.js.html b/docs/frontend_api/entities_note_short.js.html
index 69f2d1dc9..0e70fda84 100644
--- a/docs/frontend_api/entities_note_short.js.html
+++ b/docs/frontend_api/entities_note_short.js.html
@@ -30,7 +30,7 @@
 import noteAttributeCache from "../services/note_attribute_cache.js";
 import ws from "../services/ws.js";
 import options from "../services/options.js";
-import treeCache from "../services/tree_cache.js";
+import froca from "../services/tree_cache.js";
 
 const LABEL = 'label';
 const RELATION = 'relation';
@@ -48,15 +48,15 @@ const NOTE_TYPE_ICONS = {
 /**
  * FIXME: since there's no "full note" anymore we can rename this to Note
  *
- * This note's representation is used in note tree and is kept in TreeCache.
+ * This note's representation is used in note tree and is kept in Froca.
  */
 class NoteShort {
     /**
-     * @param {TreeCache} treeCache
+     * @param {Froca} froca
      * @param {Object.<string, Object>} row
      */
-    constructor(treeCache, row) {
-        this.treeCache = treeCache;
+    constructor(froca, row) {
+        this.froca = froca;
 
         /** @type {string[]} */
         this.attributes = [];
@@ -121,7 +121,7 @@ class NoteShort {
         const branchIdPos = {};
 
         for (const branchId of Object.values(this.childToBranch)) {
-            branchIdPos[branchId] = this.treeCache.getBranch(branchId).notePosition;
+            branchIdPos[branchId] = this.froca.getBranch(branchId).notePosition;
         }
 
         this.children.sort((a, b) => branchIdPos[this.childToBranch[a]] < branchIdPos[this.childToBranch[b]] ? -1 : 1);
@@ -133,7 +133,7 @@ class NoteShort {
     }
 
     async getContent() {
-        // we're not caching content since these objects are in treeCache and as such pretty long lived
+        // we're not caching content since these objects are in froca and as such pretty long lived
         const note = await server.get("notes/" + this.noteId);
 
         return note.content;
@@ -161,7 +161,7 @@ class NoteShort {
     getBranches() {
         const branchIds = Object.values(this.parentToBranch);
 
-        return this.treeCache.getBranches(branchIds);
+        return this.froca.getBranches(branchIds);
     }
 
     /** @returns {boolean} */
@@ -174,7 +174,7 @@ class NoteShort {
         // don't use Object.values() to guarantee order
         const branchIds = this.children.map(childNoteId => this.childToBranch[childNoteId]);
 
-        return this.treeCache.getBranches(branchIds);
+        return this.froca.getBranches(branchIds);
     }
 
     /** @returns {string[]} */
@@ -184,7 +184,7 @@ class NoteShort {
 
     /** @returns {NoteShort[]} */
     getParentNotes() {
-        return this.treeCache.getNotesFromCache(this.parents);
+        return this.froca.getNotesFromCache(this.parents);
     }
 
     // will sort the parents so that non-search & non-archived are first and archived at the end
@@ -197,7 +197,7 @@ class NoteShort {
                 return 1;
             }
 
-            const aNote = this.treeCache.getNoteFromCache([aNoteId]);
+            const aNote = this.froca.getNoteFromCache([aNoteId]);
 
             if (aNote.hasLabel('archived')) {
                 return 1;
@@ -214,7 +214,7 @@ class NoteShort {
 
     /** @returns {Promise<NoteShort[]>} */
     async getChildNotes() {
-        return await this.treeCache.getNotes(this.children);
+        return await this.froca.getNotes(this.children);
     }
 
     /**
@@ -224,7 +224,7 @@ class NoteShort {
      */
     getOwnedAttributes(type, name) {
         const attrs = this.attributes
-            .map(attributeId => this.treeCache.attributes[attributeId])
+            .map(attributeId => this.froca.attributes[attributeId])
             .filter(Boolean); // filter out nulls;
 
         return this.__filterAttrs(attrs, type, name);
@@ -260,7 +260,7 @@ class NoteShort {
             }
 
             for (const templateAttr of attrArrs.flat().filter(attr => attr.type === 'relation' && attr.name === 'template')) {
-                const templateNote = this.treeCache.notes[templateAttr.value];
+                const templateNote = this.froca.notes[templateAttr.value];
 
                 if (templateNote && templateNote.noteId !== this.noteId) {
                     attrArrs.push(templateNote.__getCachedAttributes(newPath));
@@ -329,8 +329,8 @@ class NoteShort {
         const notePaths = this.getAllNotePaths().map(path => ({
             notePath: path,
             isInHoistedSubTree: path.includes(hoistedNotePath),
-            isArchived: path.find(noteId => treeCache.notes[noteId].hasLabel('archived')),
-            isSearch: path.find(noteId => treeCache.notes[noteId].type === 'search')
+            isArchived: path.find(noteId => froca.notes[noteId].hasLabel('archived')),
+            isSearch: path.find(noteId => froca.notes[noteId].type === 'search')
         }));
 
         notePaths.sort((a, b) => {
@@ -608,7 +608,7 @@ class NoteShort {
         const targets = [];
 
         for (const relation of relations) {
-            targets.push(await this.treeCache.getNote(relation.value));
+            targets.push(await this.froca.getNote(relation.value));
         }
 
         return targets;
@@ -620,7 +620,7 @@ class NoteShort {
     getTemplateNotes() {
         const relations = this.getRelations('template');
 
-        return relations.map(rel => this.treeCache.notes[rel.value]);
+        return relations.map(rel => this.froca.notes[rel.value]);
     }
 
     getPromotedDefinitionAttributes() {
@@ -681,7 +681,7 @@ class NoteShort {
      */
     getTargetRelations() {
         return this.targetRelations
-            .map(attributeId => this.treeCache.attributes[attributeId]);
+            .map(attributeId => this.froca.attributes[attributeId]);
     }
 
     /**
@@ -692,7 +692,7 @@ class NoteShort {
     async getTargetRelationSourceNotes() {
         const targetRelations = this.getTargetRelations();
 
-        return await this.treeCache.getNotes(targetRelations.map(tr => tr.noteId));
+        return await this.froca.getNotes(targetRelations.map(tr => tr.noteId));
     }
 
     /**
@@ -701,7 +701,7 @@ class NoteShort {
      * @return {Promise<NoteComplement>}
      */
     async getNoteComplement() {
-        return await this.treeCache.getNoteComplement(this.noteId);
+        return await this.froca.getNoteComplement(this.noteId);
     }
 
     get toString() {
@@ -710,7 +710,7 @@ class NoteShort {
 
     get dto() {
         const dto = Object.assign({}, this);
-        delete dto.treeCache;
+        delete dto.froca;
 
         return dto;
     }
diff --git a/docs/frontend_api/note_full.js.html b/docs/frontend_api/note_full.js.html
index 097e67fb6..c930a3e57 100644
--- a/docs/frontend_api/note_full.js.html
+++ b/docs/frontend_api/note_full.js.html
@@ -32,8 +32,8 @@
  * Represents full note, specifically including note's content.
  */
 class NoteFull extends NoteShort {
-    constructor(treeCache, row) {
-        super(treeCache, row);
+    constructor(froca, row) {
+        super(froca, row);
 
         /** @param {string} */
         this.content = row.content;
diff --git a/docs/frontend_api/note_short.js.html b/docs/frontend_api/note_short.js.html
index 222ba177d..63401a301 100644
--- a/docs/frontend_api/note_short.js.html
+++ b/docs/frontend_api/note_short.js.html
@@ -27,12 +27,12 @@
     
/**
- * This note's representation is used in note tree and is kept in TreeCache.
+ * This note's representation is used in note tree and is kept in Froca.
  * Its notable omission is the note content.
  */
 class NoteShort {
-    constructor(treeCache, row) {
-        this.treeCache = treeCache;
+    constructor(froca, row) {
+        this.froca = froca;
         /** @param {string} */
         this.noteId = row.noteId;
         /** @param {string} */
@@ -55,48 +55,48 @@ class NoteShort {
 
     /** @returns {Promise<Array.<Branch>>} */
     async getBranches() {
-        const branchIds = this.treeCache.parents[this.noteId].map(
-            parentNoteId => this.treeCache.getBranchIdByChildParent(this.noteId, parentNoteId));
+        const branchIds = this.froca.parents[this.noteId].map(
+            parentNoteId => this.froca.getBranchIdByChildParent(this.noteId, parentNoteId));
 
-        return this.treeCache.getBranches(branchIds);
+        return this.froca.getBranches(branchIds);
     }
 
     /** @returns {boolean} */
     hasChildren() {
-        return this.treeCache.children[this.noteId]
-            && this.treeCache.children[this.noteId].length > 0;
+        return this.froca.children[this.noteId]
+            && this.froca.children[this.noteId].length > 0;
     }
 
     /** @returns {Promise<Array.<Branch>>} */
     async getChildBranches() {
-        if (!this.treeCache.children[this.noteId]) {
+        if (!this.froca.children[this.noteId]) {
             return [];
         }
 
-        const branchIds = this.treeCache.children[this.noteId].map(
-            childNoteId => this.treeCache.getBranchIdByChildParent(childNoteId, this.noteId));
+        const branchIds = this.froca.children[this.noteId].map(
+            childNoteId => this.froca.getBranchIdByChildParent(childNoteId, this.noteId));
 
-        return await this.treeCache.getBranches(branchIds);
+        return await this.froca.getBranches(branchIds);
     }
 
     /** @returns {Array.<string>} */
     getParentNoteIds() {
-        return this.treeCache.parents[this.noteId] || [];
+        return this.froca.parents[this.noteId] || [];
     }
 
     /** @returns {Promise<Array.<NoteShort>>} */
     async getParentNotes() {
-        return await this.treeCache.getNotes(this.getParentNoteIds());
+        return await this.froca.getNotes(this.getParentNoteIds());
     }
 
     /** @returns {Array.<string>} */
     getChildNoteIds() {
-        return this.treeCache.children[this.noteId] || [];
+        return this.froca.children[this.noteId] || [];
     }
 
     /** @returns {Promise<Array.<NoteShort>>} */
     async getChildNotes() {
-        return await this.treeCache.getNotes(this.getChildNoteIds());
+        return await this.froca.getNotes(this.getChildNoteIds());
     }
 
     get toString() {
@@ -105,7 +105,7 @@ class NoteShort {
 
     get dto() {
         const dto = Object.assign({}, this);
-        delete dto.treeCache;
+        delete dto.froca;
         delete dto.archived;
 
         return dto;
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html
index d16aeadcc..c93b483b9 100644
--- a/docs/frontend_api/services_frontend_script_api.js.html
+++ b/docs/frontend_api/services_frontend_script_api.js.html
@@ -30,7 +30,7 @@
 import utils from './utils.js';
 import toastService from './toast.js';
 import linkService from './link.js';
-import treeCache from './tree_cache.js';
+import froca from './tree_cache.js';
 import noteTooltipService from './note_tooltip.js';
 import protectedSessionService from './protected_session.js';
 import dateNotesService from './date_notes.js';
@@ -251,7 +251,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
      * @param {string} noteId
      * @return {Promise<NoteShort>}
      */
-    this.getNote = async noteId => await treeCache.getNote(noteId);
+    this.getNote = async noteId => await froca.getNote(noteId);
 
     /**
      * Returns list of notes. If note is missing from cache, it's loaded.
@@ -263,7 +263,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
      * @param {boolean} [silentNotFoundError] - don't report error if the note is not found
      * @return {Promise<NoteShort[]>}
      */
-    this.getNotes = async (noteIds, silentNotFoundError = false) => await treeCache.getNotes(noteIds, silentNotFoundError);
+    this.getNotes = async (noteIds, silentNotFoundError = false) => await froca.getNotes(noteIds, silentNotFoundError);
 
     /**
      * Update frontend tree (note) cache from the backend.
@@ -271,7 +271,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
      * @param {string[]} noteIds
      * @method
      */
-    this.reloadNotes = async noteIds => await treeCache.reloadNotes(noteIds);
+    this.reloadNotes = async noteIds => await froca.reloadNotes(noteIds);
 
     /**
      * Instance name identifies particular Trilium instance. It can be useful for scripts
diff --git a/src/entities/note.js b/src/entities/note.js
index ab1638a45..290d2e433 100644
--- a/src/entities/note.js
+++ b/src/entities/note.js
@@ -399,7 +399,7 @@ class Note extends Entity {
                 return false;
             }
 
-            // FIXME: this code is quite questionable, one problem is that other caches (TreeCache, NoteCache) have nothing like that
+            // FIXME: this code is quite questionable, one problem is that other caches (Froca, NoteCache) have nothing like that
             if (attr.isDefinition()) {
                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name);
 
diff --git a/src/public/app/dialogs/branch_prefix.js b/src/public/app/dialogs/branch_prefix.js
index 2c2c0e2d3..6ce36ed3a 100644
--- a/src/public/app/dialogs/branch_prefix.js
+++ b/src/public/app/dialogs/branch_prefix.js
@@ -1,6 +1,6 @@
 import treeService from '../services/tree.js';
 import server from '../services/server.js';
-import treeCache from "../services/tree_cache.js";
+import froca from "../services/tree_cache.js";
 import toastService from "../services/toast.js";
 import utils from "../services/utils.js";
 
@@ -18,14 +18,14 @@ export async function showDialog(notePath) {
         return;
     }
 
-    branchId = await treeCache.getBranchId(parentNoteId, noteId);
-    const branch = treeCache.getBranch(branchId);
+    branchId = await froca.getBranchId(parentNoteId, noteId);
+    const branch = froca.getBranch(branchId);
 
     if (!branch || branch.noteId === 'root') {
         return;
     }
 
-    const parentNote = await treeCache.getNote(branch.parentNoteId);
+    const parentNote = await froca.getNote(branch.parentNoteId);
 
     if (parentNote.type === 'search') {
         return;
diff --git a/src/public/app/dialogs/clone_to.js b/src/public/app/dialogs/clone_to.js
index 6ac6af422..ee4c9a76f 100644
--- a/src/public/app/dialogs/clone_to.js
+++ b/src/public/app/dialogs/clone_to.js
@@ -2,7 +2,7 @@ import noteAutocompleteService from "../services/note_autocomplete.js";
 import utils from "../services/utils.js";
 import treeService from "../services/tree.js";
 import toastService from "../services/toast.js";
-import treeCache from "../services/tree_cache.js";
+import froca from "../services/tree_cache.js";
 import branchService from "../services/branches.js";
 
 const $dialog = $("#clone-to-dialog");
@@ -29,7 +29,7 @@ export async function showDialog(noteIds) {
     $noteList.empty();
 
     for (const noteId of clonedNoteIds) {
-        const note = await treeCache.getNote(noteId);
+        const note = await froca.getNote(noteId);
 
         $noteList.append($("
  • ").text(note.title)); } @@ -40,13 +40,13 @@ export async function showDialog(noteIds) { async function cloneNotesTo(notePath) { const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath); - const targetBranchId = await treeCache.getBranchId(parentNoteId, noteId); + const targetBranchId = await froca.getBranchId(parentNoteId, noteId); for (const cloneNoteId of clonedNoteIds) { await branchService.cloneNoteTo(cloneNoteId, targetBranchId, $clonePrefix.val()); - const clonedNote = await treeCache.getNote(cloneNoteId); - const targetNote = await treeCache.getBranch(targetBranchId).getNote(); + const clonedNote = await froca.getNote(cloneNoteId); + const targetNote = await froca.getBranch(targetBranchId).getNote(); toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`); } diff --git a/src/public/app/dialogs/delete_notes.js b/src/public/app/dialogs/delete_notes.js index 20d4013bc..e04390d12 100644 --- a/src/public/app/dialogs/delete_notes.js +++ b/src/public/app/dialogs/delete_notes.js @@ -1,5 +1,5 @@ import server from "../services/server.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import linkService from "../services/link.js"; import utils from "../services/utils.js"; @@ -30,7 +30,7 @@ async function renderDeletePreview() { $deleteNotesListWrapper.toggle(response.noteIdsToBeDeleted.length > 0); $noNoteToDeleteWrapper.toggle(response.noteIdsToBeDeleted.length === 0); - for (const note of await treeCache.getNotes(response.noteIdsToBeDeleted)) { + for (const note of await froca.getNotes(response.noteIdsToBeDeleted)) { $deleteNotesList.append( $("
  • ").append( await linkService.createNoteLink(note.noteId, {showNotePath: true}) @@ -43,7 +43,7 @@ async function renderDeletePreview() { $brokenRelationsListWrapper.toggle(response.brokenRelations.length > 0); $brokenRelationsCount.text(response.brokenRelations.length); - await treeCache.getNotes(response.brokenRelations.map(br => br.noteId)); + await froca.getNotes(response.brokenRelations.map(br => br.noteId)); for (const attr of response.brokenRelations) { $brokenRelationsList.append( diff --git a/src/public/app/dialogs/export.js b/src/public/app/dialogs/export.js index bd1892044..ba4f37984 100644 --- a/src/public/app/dialogs/export.js +++ b/src/public/app/dialogs/export.js @@ -2,7 +2,7 @@ import treeService from "../services/tree.js"; import utils from "../services/utils.js"; import ws from "../services/ws.js"; import toastService from "../services/toast.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import openService from "../services/open.js"; const $dialog = $("#export-dialog"); @@ -42,7 +42,7 @@ export async function showDialog(notePath, defaultType) { const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath); - branchId = await treeCache.getBranchId(parentNoteId, noteId); + branchId = await froca.getBranchId(parentNoteId, noteId); const noteTitle = await treeService.getNoteTitle(noteId); diff --git a/src/public/app/dialogs/include_note.js b/src/public/app/dialogs/include_note.js index 0bb6de912..549c2285e 100644 --- a/src/public/app/dialogs/include_note.js +++ b/src/public/app/dialogs/include_note.js @@ -1,7 +1,7 @@ import treeService from '../services/tree.js'; import noteAutocompleteService from '../services/note_autocomplete.js'; import utils from "../services/utils.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; const $dialog = $("#include-note-dialog"); const $form = $("#include-note-form"); @@ -26,7 +26,7 @@ export async function showDialog(widget) { async function includeNote(notePath) { const noteId = treeService.getNoteIdFromNotePath(notePath); - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); const boxSize = $("input[name='include-note-box-size']:checked").val(); diff --git a/src/public/app/dialogs/move_to.js b/src/public/app/dialogs/move_to.js index 9d5408818..f8265e051 100644 --- a/src/public/app/dialogs/move_to.js +++ b/src/public/app/dialogs/move_to.js @@ -1,7 +1,7 @@ import noteAutocompleteService from "../services/note_autocomplete.js"; import utils from "../services/utils.js"; import toastService from "../services/toast.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import branchService from "../services/branches.js"; import treeService from "../services/tree.js"; @@ -22,8 +22,8 @@ export async function showDialog(branchIds) { $noteList.empty(); for (const branchId of movedBranchIds) { - const branch = treeCache.getBranch(branchId); - const note = await treeCache.getNote(branch.noteId); + const branch = froca.getBranch(branchId); + const note = await froca.getNote(branch.noteId); $noteList.append($("
  • ").text(note.title)); } @@ -35,7 +35,7 @@ export async function showDialog(branchIds) { async function moveNotesTo(parentBranchId) { await branchService.moveToParentNote(movedBranchIds, parentBranchId); - const parentBranch = treeCache.getBranch(parentBranchId); + const parentBranch = froca.getBranch(parentBranchId); const parentNote = await parentBranch.getNote(); toastService.showMessage(`Selected notes have been moved into ${parentNote.title}`); @@ -48,7 +48,7 @@ $form.on('submit', () => { $dialog.modal('hide'); const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath); - treeCache.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId)); + froca.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId)); } else { logError("No path to move to."); diff --git a/src/public/app/dialogs/recent_changes.js b/src/public/app/dialogs/recent_changes.js index 6a71e1b41..d9e4fa4b5 100644 --- a/src/public/app/dialogs/recent_changes.js +++ b/src/public/app/dialogs/recent_changes.js @@ -2,7 +2,7 @@ import linkService from '../services/link.js'; import utils from '../services/utils.js'; import server from '../services/server.js'; import treeService from "../services/tree.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import appContext from "../services/app_context.js"; import hoistedNoteService from "../services/hoisted_note.js"; @@ -19,7 +19,7 @@ export async function showDialog(ancestorNoteId) { const recentChangesRows = await server.get('recent-changes/' + ancestorNoteId); // preload all notes into cache - await treeCache.getNotes(recentChangesRows.map(r => r.noteId), true); + await froca.getNotes(recentChangesRows.map(r => r.noteId), true); $content.empty(); @@ -54,7 +54,7 @@ export async function showDialog(ancestorNoteId) { $dialog.modal('hide'); - await treeCache.reloadNotes([change.noteId]); + await froca.reloadNotes([change.noteId]); appContext.tabManager.getActiveTabContext().setNote(change.noteId); } @@ -67,7 +67,7 @@ export async function showDialog(ancestorNoteId) { } } else { - const note = await treeCache.getNote(change.noteId); + const note = await froca.getNote(change.noteId); const notePath = treeService.getSomeNotePath(note); if (notePath) { diff --git a/src/public/app/entities/attribute.js b/src/public/app/entities/attribute.js index ec826ecc3..e465062b3 100644 --- a/src/public/app/entities/attribute.js +++ b/src/public/app/entities/attribute.js @@ -1,8 +1,8 @@ import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js'; class Attribute { - constructor(treeCache, row) { - this.treeCache = treeCache; + constructor(froca, row) { + this.froca = froca; this.update(row); } @@ -28,7 +28,7 @@ class Attribute { /** @returns {NoteShort} */ getNote() { - return this.treeCache.notes[this.noteId]; + return this.froca.notes[this.noteId]; } get targetNoteId() { // alias @@ -95,7 +95,7 @@ class Attribute { get dto() { const dto = Object.assign({}, this); - delete dto.treeCache; + delete dto.froca; return dto; } diff --git a/src/public/app/entities/branch.js b/src/public/app/entities/branch.js index 3171ecd0f..1b346c626 100644 --- a/src/public/app/entities/branch.js +++ b/src/public/app/entities/branch.js @@ -1,7 +1,7 @@ /** Represents mapping between note and parent note */ class Branch { - constructor(treeCache, row) { - this.treeCache = treeCache; + constructor(froca, row) { + this.froca = froca; this.update(row); } @@ -27,17 +27,17 @@ class Branch { /** @returns {NoteShort} */ async getNote() { - return this.treeCache.getNote(this.noteId); + return this.froca.getNote(this.noteId); } /** @returns {NoteShort} */ getNoteFromCache() { - return this.treeCache.getNoteFromCache(this.noteId); + return this.froca.getNoteFromCache(this.noteId); } /** @returns {NoteShort} */ async getParentNote() { - return this.treeCache.getNote(this.parentNoteId); + return this.froca.getNote(this.parentNoteId); } /** @returns {boolean} true if it's top level, meaning its parent is root note */ diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 884b1d98a..f0b4ee621 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -2,7 +2,7 @@ import server from '../services/server.js'; import noteAttributeCache from "../services/note_attribute_cache.js"; import ws from "../services/ws.js"; import options from "../services/options.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; const LABEL = 'label'; const RELATION = 'relation'; @@ -20,15 +20,15 @@ const NOTE_TYPE_ICONS = { /** * FIXME: since there's no "full note" anymore we can rename this to Note * - * This note's representation is used in note tree and is kept in TreeCache. + * This note's representation is used in note tree and is kept in Froca. */ class NoteShort { /** - * @param {TreeCache} treeCache + * @param {Froca} froca * @param {Object.} row */ - constructor(treeCache, row) { - this.treeCache = treeCache; + constructor(froca, row) { + this.froca = froca; /** @type {string[]} */ this.attributes = []; @@ -93,7 +93,7 @@ class NoteShort { const branchIdPos = {}; for (const branchId of Object.values(this.childToBranch)) { - branchIdPos[branchId] = this.treeCache.getBranch(branchId).notePosition; + branchIdPos[branchId] = this.froca.getBranch(branchId).notePosition; } this.children.sort((a, b) => branchIdPos[this.childToBranch[a]] < branchIdPos[this.childToBranch[b]] ? -1 : 1); @@ -105,7 +105,7 @@ class NoteShort { } async getContent() { - // we're not caching content since these objects are in treeCache and as such pretty long lived + // we're not caching content since these objects are in froca and as such pretty long lived const note = await server.get("notes/" + this.noteId); return note.content; @@ -133,7 +133,7 @@ class NoteShort { getBranches() { const branchIds = Object.values(this.parentToBranch); - return this.treeCache.getBranches(branchIds); + return this.froca.getBranches(branchIds); } /** @returns {boolean} */ @@ -146,7 +146,7 @@ class NoteShort { // don't use Object.values() to guarantee order const branchIds = this.children.map(childNoteId => this.childToBranch[childNoteId]); - return this.treeCache.getBranches(branchIds); + return this.froca.getBranches(branchIds); } /** @returns {string[]} */ @@ -156,7 +156,7 @@ class NoteShort { /** @returns {NoteShort[]} */ getParentNotes() { - return this.treeCache.getNotesFromCache(this.parents); + return this.froca.getNotesFromCache(this.parents); } // will sort the parents so that non-search & non-archived are first and archived at the end @@ -169,7 +169,7 @@ class NoteShort { return 1; } - const aNote = this.treeCache.getNoteFromCache([aNoteId]); + const aNote = this.froca.getNoteFromCache([aNoteId]); if (aNote.hasLabel('archived')) { return 1; @@ -186,7 +186,7 @@ class NoteShort { /** @returns {Promise} */ async getChildNotes() { - return await this.treeCache.getNotes(this.children); + return await this.froca.getNotes(this.children); } /** @@ -196,7 +196,7 @@ class NoteShort { */ getOwnedAttributes(type, name) { const attrs = this.attributes - .map(attributeId => this.treeCache.attributes[attributeId]) + .map(attributeId => this.froca.attributes[attributeId]) .filter(Boolean); // filter out nulls; return this.__filterAttrs(attrs, type, name); @@ -224,7 +224,7 @@ class NoteShort { if (this.noteId !== 'root') { for (const parentNote of this.getParentNotes()) { - // these virtual parent-child relationships are also loaded into frontend tree cache + // these virtual parent-child relationships are also loaded into froca if (parentNote.type !== 'search') { attrArrs.push(parentNote.__getInheritableAttributes(newPath)); } @@ -232,7 +232,7 @@ class NoteShort { } for (const templateAttr of attrArrs.flat().filter(attr => attr.type === 'relation' && attr.name === 'template')) { - const templateNote = this.treeCache.notes[templateAttr.value]; + const templateNote = this.froca.notes[templateAttr.value]; if (templateNote && templateNote.noteId !== this.noteId) { attrArrs.push(templateNote.__getCachedAttributes(newPath)); @@ -301,8 +301,8 @@ class NoteShort { const notePaths = this.getAllNotePaths().map(path => ({ notePath: path, isInHoistedSubTree: path.includes(hoistedNotePath), - isArchived: path.find(noteId => treeCache.notes[noteId].hasLabel('archived')), - isSearch: path.find(noteId => treeCache.notes[noteId].type === 'search') + isArchived: path.find(noteId => froca.notes[noteId].hasLabel('archived')), + isSearch: path.find(noteId => froca.notes[noteId].type === 'search') })); notePaths.sort((a, b) => { @@ -580,7 +580,7 @@ class NoteShort { const targets = []; for (const relation of relations) { - targets.push(await this.treeCache.getNote(relation.value)); + targets.push(await this.froca.getNote(relation.value)); } return targets; @@ -592,7 +592,7 @@ class NoteShort { getTemplateNotes() { const relations = this.getRelations('template'); - return relations.map(rel => this.treeCache.notes[rel.value]); + return relations.map(rel => this.froca.notes[rel.value]); } getPromotedDefinitionAttributes() { @@ -653,7 +653,7 @@ class NoteShort { */ getTargetRelations() { return this.targetRelations - .map(attributeId => this.treeCache.attributes[attributeId]); + .map(attributeId => this.froca.attributes[attributeId]); } /** @@ -664,7 +664,7 @@ class NoteShort { async getTargetRelationSourceNotes() { const targetRelations = this.getTargetRelations(); - return await this.treeCache.getNotes(targetRelations.map(tr => tr.noteId)); + return await this.froca.getNotes(targetRelations.map(tr => tr.noteId)); } /** @@ -673,7 +673,7 @@ class NoteShort { * @return {Promise} */ async getNoteComplement() { - return await this.treeCache.getNoteComplement(this.noteId); + return await this.froca.getNoteComplement(this.noteId); } get toString() { @@ -682,7 +682,7 @@ class NoteShort { get dto() { const dto = Object.assign({}, this); - delete dto.treeCache; + delete dto.froca; return dto; } diff --git a/src/public/app/services/app_context.js b/src/public/app/services/app_context.js index 72050fd07..09ee073cf 100644 --- a/src/public/app/services/app_context.js +++ b/src/public/app/services/app_context.js @@ -1,4 +1,4 @@ -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import bundleService from "./bundle.js"; import DialogCommandExecutor from "./dialog_command_executor.js"; import Entrypoints from "./entrypoints.js"; @@ -28,7 +28,7 @@ class AppContext extends Component { } async start() { - await Promise.all([treeCache.initializedPromise, options.initializedPromise]); + await Promise.all([froca.initializedPromise, options.initializedPromise]); this.showWidgets(); diff --git a/src/public/app/services/attribute_renderer.js b/src/public/app/services/attribute_renderer.js index 08120e754..66a280967 100644 --- a/src/public/app/services/attribute_renderer.js +++ b/src/public/app/services/attribute_renderer.js @@ -1,5 +1,5 @@ import ws from "./ws.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; async function renderAttribute(attribute, renderIsInheritable) { const isInheritable = renderIsInheritable && attribute.isInheritable ? `(inheritable)` : ''; @@ -48,7 +48,7 @@ function formatValue(val) { } async function createNoteLink(noteId) { - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); if (!note) { return; diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.js index 8c7c482d0..0239709e3 100644 --- a/src/public/app/services/branches.js +++ b/src/public/app/services/branches.js @@ -1,7 +1,7 @@ import utils from './utils.js'; import server from './server.js'; import toastService from "./toast.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import hoistedNoteService from "./hoisted_note.js"; import ws from "./ws.js"; @@ -28,7 +28,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { branchIdsToMove = filterRootNote(branchIdsToMove); branchIdsToMove = filterSearchBranches(branchIdsToMove); - const afterNote = await treeCache.getBranch(afterBranchId).getNote(); + const afterNote = await froca.getBranch(afterBranchId).getNote(); if (afterNote.noteId === 'root' || afterNote.noteId === hoistedNoteService.getHoistedNoteId()) { alert('Cannot move notes after root note.'); @@ -51,7 +51,7 @@ async function moveToParentNote(branchIdsToMove, newParentBranchId) { branchIdsToMove = filterRootNote(branchIdsToMove); for (const branchIdToMove of branchIdsToMove) { - const branchToMove = treeCache.getBranch(branchIdToMove); + const branchToMove = froca.getBranch(branchIdToMove); if (branchToMove.noteId === hoistedNoteService.getHoistedNoteId() || (await branchToMove.getParentNote()).type === 'search') { @@ -91,7 +91,7 @@ async function deleteNotes(branchIdsToDelete) { const last = counter === branchIdsToDelete.length; const query = `?taskId=${taskId}&last=${last ? 'true' : 'false'}`; - const branch = treeCache.getBranch(branchIdToDelete); + const branch = froca.getBranch(branchIdToDelete); if (deleteAllClones) { await server.remove(`notes/${branch.noteId}` + query); @@ -132,7 +132,7 @@ function filterRootNote(branchIds) { const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); return branchIds.filter(branchId => { - const branch = treeCache.getBranch(branchId); + const branch = froca.getBranch(branchId); return branch.noteId !== 'root' && branch.noteId !== hoistedNoteId; diff --git a/src/public/app/services/bundle.js b/src/public/app/services/bundle.js index 24e294b1c..def06559f 100644 --- a/src/public/app/services/bundle.js +++ b/src/public/app/services/bundle.js @@ -1,7 +1,7 @@ import ScriptContext from "./script_context.js"; import server from "./server.js"; import toastService from "./toast.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import utils from "./utils.js"; async function getAndExecuteBundle(noteId, originEntity = null) { @@ -19,7 +19,7 @@ async function executeBundle(bundle, originEntity, $container) { }.call(apiContext)); } catch (e) { - const note = await treeCache.getNote(bundle.noteId); + const note = await froca.getNote(bundle.noteId); toastService.showAndLogError(`Execution of JS note "${note.title}" with ID ${bundle.noteId} failed with error: ${e.message}`); } diff --git a/src/public/app/services/clipboard.js b/src/public/app/services/clipboard.js index 56c45ebea..654b14a23 100644 --- a/src/public/app/services/clipboard.js +++ b/src/public/app/services/clipboard.js @@ -1,7 +1,7 @@ import branchService from "./branches.js"; import toastService from "./toast.js"; import hoistedNoteService from "./hoisted_note.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; let clipboardBranchIds = []; let clipboardMode = null; @@ -18,7 +18,7 @@ async function pasteAfter(afterBranchId) { clipboardMode = null; } else if (clipboardMode === 'copy') { - const clipboardBranches = clipboardBranchIds.map(branchId => treeCache.getBranch(branchId)); + const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId)); for (const clipboardBranch of clipboardBranches) { const clipboardNote = await clipboardBranch.getNote(); @@ -45,7 +45,7 @@ async function pasteInto(parentBranchId) { clipboardMode = null; } else if (clipboardMode === 'copy') { - const clipboardBranches = clipboardBranchIds.map(branchId => treeCache.getBranch(branchId)); + const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId)); for (const clipboardBranch of clipboardBranches) { const clipboardNote = await clipboardBranch.getNote(); @@ -78,7 +78,7 @@ function cut(branchIds) { } function isClipboardEmpty() { - clipboardBranchIds = clipboardBranchIds.filter(branchId => !!treeCache.getBranch(branchId)); + clipboardBranchIds = clipboardBranchIds.filter(branchId => !!froca.getBranch(branchId)); return clipboardBranchIds.length === 0; } diff --git a/src/public/app/services/date_notes.js b/src/public/app/services/date_notes.js index e7906c5b0..77c1647c6 100644 --- a/src/public/app/services/date_notes.js +++ b/src/public/app/services/date_notes.js @@ -1,4 +1,4 @@ -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import server from "./server.js"; import ws from "./ws.js"; @@ -6,7 +6,7 @@ import ws from "./ws.js"; async function getInboxNote() { const note = await server.get('date-notes/inbox/' + dayjs().format("YYYY-MM-DD"), "date-note"); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } /** @return {NoteShort} */ @@ -20,7 +20,7 @@ async function getDateNote(date) { await ws.waitForMaxKnownEntityChangeId(); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } /** @return {NoteShort} */ @@ -29,7 +29,7 @@ async function getMonthNote(month) { await ws.waitForMaxKnownEntityChangeId(); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } /** @return {NoteShort} */ @@ -38,7 +38,7 @@ async function getYearNote(year) { await ws.waitForMaxKnownEntityChangeId(); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } /** @return {NoteShort} */ @@ -47,7 +47,7 @@ async function createSqlConsole() { await ws.waitForMaxKnownEntityChangeId(); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } /** @return {NoteShort} */ @@ -56,7 +56,7 @@ async function createSearchNote(opts = {}) { await ws.waitForMaxKnownEntityChangeId(); - return await treeCache.getNote(note.noteId); + return await froca.getNote(note.noteId); } export default { diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 935c6b819..f8420b28d 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -2,7 +2,7 @@ import server from './server.js'; import utils from './utils.js'; import toastService from './toast.js'; import linkService from './link.js'; -import treeCache from './tree_cache.js'; +import froca from './tree_cache.js'; import noteTooltipService from './note_tooltip.js'; import protectedSessionService from './protected_session.js'; import dateNotesService from './date_notes.js'; @@ -223,7 +223,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain * @param {string} noteId * @return {Promise} */ - this.getNote = async noteId => await treeCache.getNote(noteId); + this.getNote = async noteId => await froca.getNote(noteId); /** * Returns list of notes. If note is missing from cache, it's loaded. @@ -235,7 +235,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain * @param {boolean} [silentNotFoundError] - don't report error if the note is not found * @return {Promise} */ - this.getNotes = async (noteIds, silentNotFoundError = false) => await treeCache.getNotes(noteIds, silentNotFoundError); + this.getNotes = async (noteIds, silentNotFoundError = false) => await froca.getNotes(noteIds, silentNotFoundError); /** * Update frontend tree (note) cache from the backend. @@ -243,7 +243,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain * @param {string[]} noteIds * @method */ - this.reloadNotes = async noteIds => await treeCache.reloadNotes(noteIds); + this.reloadNotes = async noteIds => await froca.reloadNotes(noteIds); /** * Instance name identifies particular Trilium instance. It can be useful for scripts diff --git a/src/public/app/services/glob.js b/src/public/app/services/glob.js index 50bfbd75f..dcb1158e6 100644 --- a/src/public/app/services/glob.js +++ b/src/public/app/services/glob.js @@ -4,7 +4,7 @@ import server from "./server.js"; import libraryLoader from "./library_loader.js"; import ws from "./ws.js"; import protectedSessionHolder from "./protected_session_holder.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; function setupGlobs() { window.glob.PROFILING_LOG = false; @@ -20,7 +20,7 @@ function setupGlobs() { window.glob.requireLibrary = libraryLoader.requireLibrary; window.glob.ESLINT = libraryLoader.ESLINT; window.glob.appContext = appContext; // for debugging - window.glob.treeCache = treeCache; + window.glob.froca = froca; // for CKEditor integration (button on block toolbar) window.glob.importMarkdownInline = async () => { diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 0b759ca91..318fb1620 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -1,7 +1,7 @@ import treeService from './tree.js'; import contextMenu from "./context_menu.js"; import appContext from "./app_context.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import utils from "./utils.js"; function getNotePathFromUrl(url) { @@ -138,7 +138,7 @@ function linkContextMenu(e) { } async function loadReferenceLinkTitle(noteId, $el) { - const note = await treeCache.getNote(noteId, true); + const note = await froca.getNote(noteId, true); let title; diff --git a/src/public/app/services/link_map.js b/src/public/app/services/link_map.js index ec696cc15..2d233f39a 100644 --- a/src/public/app/services/link_map.js +++ b/src/public/app/services/link_map.js @@ -1,6 +1,6 @@ import libraryLoader from "./library_loader.js"; import server from "./server.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import linkService from "./link.js"; const linkOverlays = [ @@ -63,14 +63,14 @@ export default class LinkMap { noteIds.add(this.note.noteId); } - await treeCache.getNotes(Array.from(noteIds)); + await froca.getNotes(Array.from(noteIds)); // pre-fetch the link titles, it's important to have hte construction afterwards synchronous // since jsPlumb caculates width of the element const $linkTitles = {}; for (const noteId of noteIds) { - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); $linkTitles[noteId] = await linkService.createNoteLink(noteId, {title: note.title}); @@ -85,7 +85,7 @@ export default class LinkMap { } // preload all notes - const notes = await treeCache.getNotes(Array.from(noteIds), true); + const notes = await froca.getNotes(Array.from(noteIds), true); const graph = new Springy.Graph(); graph.addNodes(...noteIds); diff --git a/src/public/app/services/load_results.js b/src/public/app/services/load_results.js index a75cae9ff..16d5f508e 100644 --- a/src/public/app/services/load_results.js +++ b/src/public/app/services/load_results.js @@ -1,6 +1,6 @@ export default class LoadResults { - constructor(treeCache) { - this.treeCache = treeCache; + constructor(froca) { + this.froca = froca; this.noteIdToSourceId = {}; this.sourceIdToNoteIds = {}; @@ -38,7 +38,7 @@ export default class LoadResults { getBranches() { return this.branches - .map(row => this.treeCache.branches[row.branchId]) + .map(row => this.froca.branches[row.branchId]) .filter(branch => !!branch); } @@ -58,7 +58,7 @@ export default class LoadResults { getAttributes(sourceId = 'none') { return this.attributes .filter(row => row.sourceId !== sourceId) - .map(row => this.treeCache.attributes[row.attributeId]) + .map(row => this.froca.attributes[row.attributeId]) .filter(attr => !!attr); } diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index 2de6c0276..be3b6ed9f 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -3,7 +3,7 @@ import appContext from "./app_context.js"; import utils from './utils.js'; import noteCreateService from './note_create.js'; import treeService from './tree.js'; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; // this key needs to have this value so it's hit by the tooltip const SELECTED_NOTE_PATH_KEY = "data-note-path"; @@ -252,7 +252,7 @@ function init() { } $.fn.setNote = async function (noteId) { - const note = noteId ? await treeCache.getNote(noteId, true) : null; + const note = noteId ? await froca.getNote(noteId, true) : null; $(this) .val(note ? note.title : "") diff --git a/src/public/app/services/note_content_renderer.js b/src/public/app/services/note_content_renderer.js index e10f6c2e5..0b68113c0 100644 --- a/src/public/app/services/note_content_renderer.js +++ b/src/public/app/services/note_content_renderer.js @@ -4,7 +4,7 @@ import protectedSessionService from "./protected_session.js"; import protectedSessionHolder from "./protected_session_holder.js"; import libraryLoader from "./library_loader.js"; import openService from "./open.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; async function getRenderedContent(note, options = {}) { options = Object.assign({ @@ -17,7 +17,7 @@ async function getRenderedContent(note, options = {}) { const $renderedContent = $('
    '); if (type === 'text') { - const noteComplement = await treeCache.getNoteComplement(note.noteId); + const noteComplement = await froca.getNoteComplement(note.noteId); $renderedContent.append($('
    ').html(trim(noteComplement.content, options.trim))); diff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.js index cc7aa4380..edf850d92 100644 --- a/src/public/app/services/note_create.js +++ b/src/public/app/services/note_create.js @@ -3,7 +3,7 @@ import utils from "./utils.js"; import protectedSessionHolder from "./protected_session_holder.js"; import server from "./server.js"; import ws from "./ws.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import treeService from "./tree.js"; import toastService from "./toast.js"; @@ -59,8 +59,8 @@ async function createNote(parentNotePath, options = {}) { } } - const noteEntity = await treeCache.getNote(note.noteId); - const branchEntity = treeCache.getBranch(branch.branchId); + const noteEntity = await froca.getNote(note.noteId); + const branchEntity = froca.getBranch(branch.branchId); return { note: noteEntity, @@ -93,7 +93,7 @@ async function duplicateSubtree(noteId, parentNotePath) { const activeTabContext = appContext.tabManager.getActiveTabContext(); activeTabContext.setNote(`${parentNotePath}/${note.noteId}`); - const origNote = await treeCache.getNote(noteId); + const origNote = await froca.getNote(noteId); toastService.showMessage(`Note "${origNote.title}" has been duplicated`); } diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js index 10c0b8fc6..abd9919e7 100644 --- a/src/public/app/services/note_list_renderer.js +++ b/src/public/app/services/note_list_renderer.js @@ -1,6 +1,6 @@ import linkService from "./link.js"; import noteContentRenderer from "./note_content_renderer.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import attributeService from "./attributes.js"; import attributeRenderer from "./attribute_renderer.js"; @@ -268,7 +268,7 @@ class NoteListRenderer { const endIdx = startIdx + this.pageSize; const pageNoteIds = this.noteIds.slice(startIdx, Math.min(endIdx, this.noteIds.length)); - const pageNotes = await treeCache.getNotes(pageNoteIds); + const pageNotes = await froca.getNotes(pageNoteIds); for (const note of pageNotes) { const $card = await this.renderNote(note, this.parentNote.hasLabel('expanded')); diff --git a/src/public/app/services/note_tooltip.js b/src/public/app/services/note_tooltip.js index f8451c987..dd009e7fb 100644 --- a/src/public/app/services/note_tooltip.js +++ b/src/public/app/services/note_tooltip.js @@ -1,6 +1,6 @@ import treeService from "./tree.js"; import linkService from "./link.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import utils from "./utils.js"; import attributeRenderer from "./attribute_renderer.js"; import noteContentRenderer from "./note_content_renderer.js"; @@ -44,7 +44,7 @@ async function mouseEnterHandler() { const noteId = treeService.getNoteIdFromNotePath(notePath); - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); const content = await renderTooltip(note); if (utils.isHtmlEmpty(content)) { diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.js index 46b83b5a3..d62511681 100644 --- a/src/public/app/services/protected_session.js +++ b/src/public/app/services/protected_session.js @@ -4,7 +4,7 @@ import protectedSessionHolder from './protected_session_holder.js'; import toastService from "./toast.js"; import ws from "./ws.js"; import appContext from "./app_context.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; let protectedSessionDeferred = null; @@ -32,12 +32,12 @@ function enterProtectedSession() { } async function reloadData() { - const allNoteIds = Object.keys(treeCache.notes); + const allNoteIds = Object.keys(froca.notes); - await treeCache.loadInitialTree(); + await froca.loadInitialTree(); // make sure that all notes used in the application are loaded, including the ones not shown in the tree - await treeCache.reloadNotes(allNoteIds, true); + await froca.reloadNotes(allNoteIds, true); } async function setupProtectedSession(password) { @@ -53,7 +53,7 @@ async function setupProtectedSession(password) { await reloadData(); - await appContext.triggerEvent('treeCacheReloaded'); + await appContext.triggerEvent('frocaReloaded'); appContext.triggerEvent('protectedSessionStarted'); diff --git a/src/public/app/services/script_context.js b/src/public/app/services/script_context.js index fdd23c358..005224afc 100644 --- a/src/public/app/services/script_context.js +++ b/src/public/app/services/script_context.js @@ -1,14 +1,14 @@ import FrontendScriptApi from './frontend_script_api.js'; import utils from './utils.js'; -import treeCache from './tree_cache.js'; +import froca from './tree_cache.js'; async function ScriptContext(startNoteId, allNoteIds, originEntity = null, $container = null) { const modules = {}; - await treeCache.initializedPromise; + await froca.initializedPromise; - const startNote = await treeCache.getNote(startNoteId); - const allNotes = await treeCache.getNotes(allNoteIds); + const startNote = await froca.getNote(startNoteId); + const allNotes = await froca.getNotes(allNoteIds); return { modules: modules, diff --git a/src/public/app/services/search.js b/src/public/app/services/search.js index c031a00aa..7910e271c 100644 --- a/src/public/app/services/search.js +++ b/src/public/app/services/search.js @@ -1,5 +1,5 @@ import server from "./server.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; async function searchForNoteIds(searchString) { return await server.get('search/' + encodeURIComponent(searchString)); @@ -8,7 +8,7 @@ async function searchForNoteIds(searchString) { async function searchForNotes(searchString) { const noteIds = await searchForNoteIds(searchString); - return await treeCache.getNotes(noteIds); + return await froca.getNotes(noteIds); } export default { diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index 5d5c70f60..ff7c440c2 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -4,7 +4,7 @@ import utils from "./utils.js"; import appContext from "./app_context.js"; import treeService from "./tree.js"; import Component from "../widgets/component.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import hoistedNoteService from "./hoisted_note.js"; class TabContext extends Component { @@ -74,7 +74,7 @@ class TabContext extends Component { async getResolvedNotePath(inputNotePath) { const noteId = treeService.getNoteIdFromNotePath(inputNotePath); - if ((await treeCache.getNote(noteId)).isDeleted) { + if ((await froca.getNote(noteId)).isDeleted) { // no point in trying to resolve canonical notePath return inputNotePath; } @@ -95,18 +95,18 @@ class TabContext extends Component { } // if user choise to unhoist, cache was reloaded, but might not contain this note (since it's on unexpanded path) - await treeCache.getNote(noteId); + await froca.getNote(noteId); return resolvedNotePath; } /** @property {NoteShort} */ get note() { - if (this.noteId && !(this.noteId in treeCache.notes)) { + if (this.noteId && !(this.noteId in froca.notes)) { logError(`Cannot find tabContext's note id='${this.noteId}'`); } - return treeCache.notes[this.noteId]; + return froca.notes[this.noteId]; } /** @property {string[]} */ @@ -120,7 +120,7 @@ class TabContext extends Component { return null; } - return await treeCache.getNoteComplement(this.noteId); + return await froca.getNoteComplement(this.noteId); } isActive() { @@ -159,7 +159,7 @@ class TabContext extends Component { async entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteReloaded(this.noteId)) { - const note = await treeCache.getNote(this.noteId); + const note = await froca.getNote(this.noteId); if (note.isDeleted) { this.noteId = null; diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 238694857..9ecbed53f 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -2,7 +2,7 @@ import Component from "../widgets/component.js"; import SpacedUpdate from "./spaced_update.js"; import server from "./server.js"; import options from "./options.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import treeService from "./tree.js"; import utils from "./utils.js"; import TabContext from "./tab_context.js"; @@ -47,7 +47,7 @@ export default class TabManager extends Component { const notePath = window.location.hash.substr(1); const noteId = treeService.getNoteIdFromNotePath(notePath); - if (noteId && await treeCache.noteExists(noteId)) { + if (noteId && await froca.noteExists(noteId)) { for (const tab of tabsToOpen) { tab.active = false; } @@ -72,7 +72,7 @@ export default class TabManager extends Component { for (const openTab of tabsToOpen) { const noteId = treeService.getNoteIdFromNotePath(openTab.notePath); - if (await treeCache.noteExists(noteId)) { + if (await froca.noteExists(noteId)) { // note doesn't exist so don't try to open tab for it filteredTabs.push(openTab); } diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js index 1d7f40fb0..1dbd2a4b4 100644 --- a/src/public/app/services/tree.js +++ b/src/public/app/services/tree.js @@ -1,7 +1,7 @@ import ws from './ws.js'; import utils from './utils.js'; import server from './server.js'; -import treeCache from './tree_cache.js'; +import froca from './tree_cache.js'; import hoistedNoteService from '../services/hoisted_note.js'; import appContext from "./app_context.js"; @@ -49,7 +49,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr const parentNoteId = path[i++]; if (childNoteId !== null) { - const child = await treeCache.getNote(childNoteId); + const child = await froca.getNote(childNoteId); if (!child) { console.log(`Can't find note ${childNoteId}`); @@ -70,7 +70,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr if (!parents.some(p => p.noteId === parentNoteId)) { if (logErrors) { - const parent = treeCache.getNoteFromCache(parentNoteId); + const parent = froca.getNoteFromCache(parentNoteId); console.log(utils.now(), `Did not find parent ${parentNoteId} (${parent ? parent.title : 'n/a'}) for child ${childNoteId} (${child.title}), available parents: ${parents.map(p => `${p.noteId} (${p.title})`)}`); } @@ -99,7 +99,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr return effectivePathSegments; } else { - const note = await treeCache.getNote(getNoteIdFromNotePath(notePath)); + const note = await froca.getNote(getNoteIdFromNotePath(notePath)); const someNotePathSegments = getSomeNotePathSegments(note, hoistedNoteId); @@ -158,7 +158,7 @@ function getNoteIdFromNotePath(notePath) { async function getBranchIdFromNotePath(notePath) { const {noteId, parentNoteId} = getNoteIdAndParentIdFromNotePath(notePath); - return await treeCache.getBranchId(parentNoteId, noteId); + return await froca.getBranchId(parentNoteId, noteId); } function getNoteIdAndParentIdFromNotePath(notePath) { @@ -213,7 +213,7 @@ function getNotePath(node) { async function getNoteTitle(noteId, parentNoteId = null) { utils.assertArguments(noteId); - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); if (!note) { return "[not found]"; } @@ -224,7 +224,7 @@ async function getNoteTitle(noteId, parentNoteId = null) { const branchId = note.parentToBranch[parentNoteId]; if (branchId) { - const branch = treeCache.getBranch(branchId); + const branch = froca.getBranch(branchId); if (branch && branch.prefix) { title = `${branch.prefix} - ${title}`; diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js index 4b9e2f7f5..569796906 100644 --- a/src/public/app/services/tree_cache.js +++ b/src/public/app/services/tree_cache.js @@ -6,14 +6,14 @@ import appContext from "./app_context.js"; import NoteComplement from "../entities/note_complement.js"; /** - * TreeCache keeps a read only cache of note tree structure in frontend's memory. + * Froca keeps a read only cache of note tree structure in frontend's memory. * - notes are loaded lazily when unknown noteId is requested * - when note is loaded, all its parent and child branches are loaded as well. For a branch to be used, it's not must be loaded before * - deleted notes are present in the cache as well, but they don't have any branches. As a result check for deleted branch is done by presence check - if the branch is not there even though the corresponding note has been loaded, we can infer it is deleted. * * Note and branch deletions are corner cases and usually not needed. */ -class TreeCache { +class Froca { constructor() { this.initializedPromise = this.loadInitialTree(); } @@ -181,9 +181,9 @@ class TreeCache { } // reset all the virtual branches from old search results - if (note.noteId in treeCache.notes) { - treeCache.notes[note.noteId].children = []; - treeCache.notes[note.noteId].childToBranch = {}; + if (note.noteId in froca.notes) { + froca.notes[note.noteId].children = []; + froca.notes[note.noteId].childToBranch = {}; } const branches = [...note.getBranches(), ...note.getChildBranches()]; @@ -204,7 +204,7 @@ class TreeCache { attributes: [] }); - treeCache.notes[note.noteId].searchResultsLoaded = true; + froca.notes[note.noteId].searchResultsLoaded = true; } /** @return {NoteShort[]} */ @@ -320,6 +320,6 @@ class TreeCache { } } -const treeCache = new TreeCache(); +const froca = new Froca(); -export default treeCache; +export default froca; diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index 92c9989ea..55e582ea4 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -1,5 +1,5 @@ import treeService from './tree.js'; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import clipboard from './clipboard.js'; import noteCreateService from "./note_create.js"; import contextMenu from "./context_menu.js"; @@ -36,11 +36,11 @@ class TreeContextMenu { } async getMenuItems() { - const note = await treeCache.getNote(this.node.data.noteId); - const branch = treeCache.getBranch(this.node.data.branchId); + const note = await froca.getNote(this.node.data.noteId); + const branch = froca.getBranch(this.node.data.branchId); const isNotRoot = note.noteId !== 'root'; const isHoisted = note.noteId === appContext.tabManager.getActiveTabContext().hoistedNoteId; - const parentNote = isNotRoot ? await treeCache.getNote(branch.parentNoteId) : null; + const parentNote = isNotRoot ? await froca.getNote(branch.parentNoteId) : null; // some actions don't support multi-note so they are disabled when notes are selected // the only exception is when the only selected note is the one that was right-clicked, then diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js index e2b171566..9637a4836 100644 --- a/src/public/app/services/ws.js +++ b/src/public/app/services/ws.js @@ -5,7 +5,7 @@ import LoadResults from "./load_results.js"; import Branch from "../entities/branch.js"; import Attribute from "../entities/attribute.js"; import options from "./options.js"; -import treeCache from "./tree_cache.js"; +import froca from "./tree_cache.js"; import noteAttributeCache from "./note_attribute_cache.js"; const messageHandlers = []; @@ -213,10 +213,10 @@ setTimeout(() => { }, 0); async function processEntityChanges(entityChanges) { - const loadResults = new LoadResults(treeCache); + const loadResults = new LoadResults(froca); for (const ec of entityChanges.filter(ec => ec.entityName === 'notes')) { - const note = treeCache.notes[ec.entityId]; + const note = froca.notes[ec.entityId]; if (note) { note.update(ec.entity); @@ -225,9 +225,9 @@ async function processEntityChanges(entityChanges) { } for (const ec of entityChanges.filter(ec => ec.entityName === 'branches')) { - let branch = treeCache.branches[ec.entityId]; - const childNote = treeCache.notes[ec.entity.noteId]; - const parentNote = treeCache.notes[ec.entity.parentNoteId]; + let branch = froca.branches[ec.entityId]; + const childNote = froca.notes[ec.entity.noteId]; + const parentNote = froca.notes[ec.entity.parentNoteId]; if (branch) { branch.update(ec.entity); @@ -256,8 +256,8 @@ async function processEntityChanges(entityChanges) { } else if (!ec.entity.isDeleted) { if (childNote || parentNote) { - branch = new Branch(treeCache, ec.entity); - treeCache.branches[branch.branchId] = branch; + branch = new Branch(froca, ec.entity); + froca.branches[branch.branchId] = branch; loadResults.addBranch(ec.entityId, ec.sourceId); @@ -276,7 +276,7 @@ async function processEntityChanges(entityChanges) { const parentNoteIdsToSort = new Set(); for (const branchId in ec.positions) { - const branch = treeCache.branches[branchId]; + const branch = froca.branches[branchId]; if (branch) { branch.notePosition = ec.positions[branchId]; @@ -286,7 +286,7 @@ async function processEntityChanges(entityChanges) { } for (const parentNoteId of parentNoteIdsToSort) { - const parentNote = treeCache.notes[parentNoteId]; + const parentNote = froca.notes[parentNoteId]; if (parentNote) { parentNote.sortChildren(); @@ -298,9 +298,9 @@ async function processEntityChanges(entityChanges) { // missing reloading the relation target note for (const ec of entityChanges.filter(ec => ec.entityName === 'attributes')) { - let attribute = treeCache.attributes[ec.entityId]; - const sourceNote = treeCache.notes[ec.entity.noteId]; - const targetNote = ec.entity.type === 'relation' && treeCache.notes[ec.entity.value]; + let attribute = froca.attributes[ec.entityId]; + const sourceNote = froca.notes[ec.entity.noteId]; + const targetNote = ec.entity.type === 'relation' && froca.notes[ec.entity.value]; if (attribute) { attribute.update(ec.entity); @@ -318,9 +318,9 @@ async function processEntityChanges(entityChanges) { } else if (!ec.entity.isDeleted) { if (sourceNote || targetNote) { - attribute = new Attribute(treeCache, ec.entity); + attribute = new Attribute(froca, ec.entity); - treeCache.attributes[attribute.attributeId] = attribute; + froca.attributes[attribute.attributeId] = attribute; loadResults.addAttribute(ec.entityId, ec.sourceId); @@ -336,7 +336,7 @@ async function processEntityChanges(entityChanges) { } for (const ec of entityChanges.filter(ec => ec.entityName === 'note_contents')) { - delete treeCache.noteComplementPromises[ec.entityId]; + delete froca.noteComplementPromises[ec.entityId]; loadResults.addNoteContent(ec.entityId, ec.sourceId); } @@ -358,20 +358,20 @@ async function processEntityChanges(entityChanges) { const missingNoteIds = []; for (const {entityName, entity} of entityChanges) { - if (entityName === 'branches' && !(entity.parentNoteId in treeCache.notes)) { + if (entityName === 'branches' && !(entity.parentNoteId in froca.notes)) { missingNoteIds.push(entity.parentNoteId); } else if (entityName === 'attributes' && entity.type === 'relation' && entity.name === 'template' - && !(entity.value in treeCache.notes)) { + && !(entity.value in froca.notes)) { missingNoteIds.push(entity.value); } } if (missingNoteIds.length > 0) { - await treeCache.reloadNotes(missingNoteIds); + await froca.reloadNotes(missingNoteIds); } if (!loadResults.isEmpty()) { diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index 5a88809db..a9ac419d6 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -1,5 +1,5 @@ import server from "../../services/server.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import treeService from "../../services/tree.js"; import linkService from "../../services/link.js"; import attributeAutocompleteService from "../../services/attribute_autocomplete.js"; @@ -429,7 +429,7 @@ export default class AttributeDetailWidget extends TabAwareWidget { .setSelectedNotePath(""); if (attribute.value) { - const targetNote = await treeCache.getNote(attribute.value); + const targetNote = await froca.getNote(attribute.value); if (targetNote) { this.$inputTargetNote @@ -542,7 +542,7 @@ export default class AttributeDetailWidget extends TabAwareWidget { this.$relatedNotesList.empty(); const displayedResults = results.length <= DISPLAYED_NOTES ? results : results.slice(0, DISPLAYED_NOTES); - const displayedNotes = await treeCache.getNotes(displayedResults.map(res => res.noteId)); + const displayedNotes = await froca.getNotes(displayedResults.map(res => res.noteId)); for (const note of displayedNotes) { const notePath = treeService.getSomeNotePath(note); diff --git a/src/public/app/widgets/attribute_widgets/attribute_editor.js b/src/public/app/widgets/attribute_widgets/attribute_editor.js index 18a1ccfa5..233ec88f5 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_editor.js +++ b/src/public/app/widgets/attribute_widgets/attribute_editor.js @@ -4,7 +4,7 @@ import server from "../../services/server.js"; import contextMenuService from "../../services/context_menu.js"; import attributesParser from "../../services/attribute_parser.js"; import libraryLoader from "../../services/library_loader.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import attributeRenderer from "../../services/attribute_renderer.js"; import noteCreateService from "../../services/note_create.js"; import treeService from "../../services/tree.js"; @@ -446,7 +446,7 @@ export default class AttributeEditorWidget extends TabAwareWidget { } async loadReferenceLinkTitle(noteId, $el) { - const note = await treeCache.getNote(noteId, true); + const note = await froca.getNote(noteId, true); let title; diff --git a/src/public/app/widgets/collapsible_widgets/edited_notes.js b/src/public/app/widgets/collapsible_widgets/edited_notes.js index 3f6851e73..f2d5588db 100644 --- a/src/public/app/widgets/collapsible_widgets/edited_notes.js +++ b/src/public/app/widgets/collapsible_widgets/edited_notes.js @@ -1,7 +1,7 @@ import CollapsibleWidget from "../collapsible_widget.js"; import linkService from "../../services/link.js"; import server from "../../services/server.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; const TPL = `
    @@ -54,7 +54,7 @@ export default class EditedNotesWidget extends CollapsibleWidget { const noteIds = editedNotes.flatMap(n => n.noteId); - await treeCache.getNotes(noteIds, true); // preload all at once + await froca.getNotes(noteIds, true); // preload all at once for (const editedNote of editedNotes) { const $item = $('
    '); diff --git a/src/public/app/widgets/collapsible_widgets/link_map.js b/src/public/app/widgets/collapsible_widgets/link_map.js index 2e6fee076..c7c681382 100644 --- a/src/public/app/widgets/collapsible_widgets/link_map.js +++ b/src/public/app/widgets/collapsible_widgets/link_map.js @@ -1,5 +1,5 @@ import CollapsibleWidget from "../collapsible_widget.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; let linkMapContainerIdCtr = 1; @@ -105,7 +105,7 @@ export default class LinkMapWidget extends CollapsibleWidget { const $linkMapContainer = this.$body.find('.link-map-container'); for (const noteId of changedNoteIds) { - const note = treeCache.notes[noteId]; + const note = froca.notes[noteId]; if (note) { $linkMapContainer.find(`a[data-note-path="${noteId}"]`).text(note.title); diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index f8375a03b..402d0da3e 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -2,7 +2,7 @@ import hoistedNoteService from "../services/hoisted_note.js"; import treeService from "../services/tree.js"; import utils from "../services/utils.js"; import contextMenu from "../services/context_menu.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import branchService from "../services/branches.js"; import ws from "../services/ws.js"; import TabAwareWidget from "./tab_aware_widget.js"; @@ -492,8 +492,8 @@ export default class NoteTreeWidget extends TabAwareWidget { return; } - data.result = treeCache.loadSearchNote(noteId).then(() => { - const note = treeCache.getNoteFromCache(noteId); + data.result = froca.loadSearchNote(noteId).then(() => { + const note = froca.getNoteFromCache(noteId); let childNoteIds = note.getChildNoteIds(); @@ -501,15 +501,15 @@ export default class NoteTreeWidget extends TabAwareWidget { childNoteIds = childNoteIds.slice(0, MAX_SEARCH_RESULTS_IN_TREE); } - return treeCache.getNotes(childNoteIds); + return froca.getNotes(childNoteIds); }).then(() => { - const note = treeCache.getNoteFromCache(noteId); + const note = froca.getNoteFromCache(noteId); return this.prepareChildren(note); }); } else { - data.result = treeCache.loadSubTree(noteId).then(note => this.prepareChildren(note)); + data.result = froca.loadSubTree(noteId).then(note => this.prepareChildren(note)); } }, clones: { @@ -524,7 +524,7 @@ export default class NoteTreeWidget extends TabAwareWidget { return; } - const note = await treeCache.getNote(node.data.noteId); + const note = await froca.getNote(node.data.noteId); const activeTabContext = appContext.tabManager.getActiveTabContext(); const $span = $(node.span); @@ -600,7 +600,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } prepareRootNode() { - return this.prepareNode(treeCache.getBranch('root')); + return this.prepareNode(froca.getBranch('root')); } /** @@ -637,8 +637,8 @@ export default class NoteTreeWidget extends TabAwareWidget { } updateNode(node) { - const note = treeCache.getNoteFromCache(node.data.noteId); - const branch = treeCache.getBranch(node.data.branchId); + const note = froca.getNoteFromCache(node.data.noteId); + const branch = froca.getBranch(node.data.branchId); if (!note) { console.log(`Node update not possible because note ${node.data.noteId} was not found.`); @@ -765,7 +765,7 @@ export default class NoteTreeWidget extends TabAwareWidget { const {branchIds} = await server.put(`branches/${node.data.branchId}/expanded-subtree/${isExpanded ? 1 : 0}`); - treeCache.getBranches(branchIds, true) + froca.getBranches(branchIds, true) .forEach(branch => branch.isExpanded = !!isExpanded); await this.batchUpdate(async () => { @@ -854,7 +854,7 @@ export default class NoteTreeWidget extends TabAwareWidget { // although previous line should set the expanded status, it seems to happen asynchronously // so we need to make sure it is set properly before calling updateNode which uses this flag - const branch = treeCache.getBranch(parentNode.data.branchId); + const branch = froca.getBranch(parentNode.data.branchId); branch.isExpanded = true; } @@ -873,7 +873,7 @@ export default class NoteTreeWidget extends TabAwareWidget { // these are real notes with real notePath, user can display them in a detail // but they don't have a node in the tree - const childNote = await treeCache.getNote(childNoteId); + const childNote = await froca.getNote(childNoteId); if (!childNote || childNote.type !== 'image') { ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteService.getHoistedNoteId()}, requested path is ${notePath}`); @@ -905,7 +905,7 @@ export default class NoteTreeWidget extends TabAwareWidget { getNodesByBranchId(branchId) { utils.assertArguments(branchId); - const branch = treeCache.getBranch(branchId); + const branch = froca.getBranch(branchId); return this.getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId); } @@ -1044,7 +1044,7 @@ export default class NoteTreeWidget extends TabAwareWidget { noteIdsToReload.add(attr.noteId); } else if (attr.type === 'relation' && attr.name === 'imageLink') { - const note = treeCache.getNoteFromCache(attr.noteId); + const note = froca.getNoteFromCache(attr.noteId); if (note && note.getChildNoteIds().includes(attr.value)) { // there's new/deleted imageLink betwen note and its image child - which can show/hide @@ -1088,9 +1088,9 @@ export default class NoteTreeWidget extends TabAwareWidget { if (!found) { // make sure it's loaded - await treeCache.getNote(branch.noteId); + await froca.getNote(branch.noteId); - // we're forcing lazy since it's not clear if the whole required subtree is in tree cache + // we're forcing lazy since it's not clear if the whole required subtree is in froca parentNode.addChildren([this.prepareNode(branch, true)]); this.sortChildren(parentNode); @@ -1180,8 +1180,8 @@ export default class NoteTreeWidget extends TabAwareWidget { sortChildren(node) { node.sortChildren((nodeA, nodeB) => { - const branchA = treeCache.branches[nodeA.data.branchId]; - const branchB = treeCache.branches[nodeB.data.branchId]; + const branchA = froca.branches[nodeA.data.branchId]; + const branchB = froca.branches[nodeB.data.branchId]; if (!branchA || !branchB) { return 0; @@ -1194,7 +1194,7 @@ export default class NoteTreeWidget extends TabAwareWidget { setExpanded(branchId, isExpanded) { utils.assertArguments(branchId); - const branch = treeCache.getBranch(branchId, true); + const branch = froca.getBranch(branchId, true); if (!branch) { if (branchId && branchId.startsWith('virt')) { @@ -1254,7 +1254,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } } - treeCacheReloadedEvent() { + frocaReloadedEvent() { this.reloadTreeFromCache(); } @@ -1304,7 +1304,7 @@ export default class NoteTreeWidget extends TabAwareWidget { return false; } - const parentNote = treeCache.getNoteFromCache(node.getParent().data.noteId); + const parentNote = froca.getNoteFromCache(node.getParent().data.noteId); if (parentNote && parentNote.hasLabel('sorted')) { return false; @@ -1469,13 +1469,13 @@ export default class NoteTreeWidget extends TabAwareWidget { const nodesToDuplicate = this.getSelectedOrActiveNodes(node); for (const nodeToDuplicate of nodesToDuplicate) { - const note = treeCache.getNoteFromCache(nodeToDuplicate.data.noteId); + const note = froca.getNoteFromCache(nodeToDuplicate.data.noteId); if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { continue; } - const branch = treeCache.getBranch(nodeToDuplicate.data.branchId); + const branch = froca.getBranch(nodeToDuplicate.data.branchId); noteCreateService.duplicateSubtree(nodeToDuplicate.data.noteId, branch.parentNoteId); } diff --git a/src/public/app/widgets/quick_search.js b/src/public/app/widgets/quick_search.js index ba69fdd48..aef337bde 100644 --- a/src/public/app/widgets/quick_search.js +++ b/src/public/app/widgets/quick_search.js @@ -2,7 +2,7 @@ import BasicWidget from "./basic_widget.js"; import server from "../services/server.js"; import linkService from "../services/link.js"; import dateNotesService from "../services/date_notes.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import utils from "../services/utils.js"; import appContext from "../services/app_context.js"; @@ -90,7 +90,7 @@ export default class QuickSearchWidget extends BasicWidget { this.$dropdownMenu.append('No results found'); } - for (const note of await treeCache.getNotes(displayedNoteIds)) { + for (const note of await froca.getNotes(displayedNoteIds)) { const $link = await linkService.createNoteLink(note.noteId, {showNotePath: true}); $link.addClass('dropdown-item'); $link.attr("tabIndex", "0"); diff --git a/src/public/app/widgets/similar_notes.js b/src/public/app/widgets/similar_notes.js index 377346618..0e056d947 100644 --- a/src/public/app/widgets/similar_notes.js +++ b/src/public/app/widgets/similar_notes.js @@ -1,6 +1,6 @@ import linkService from "../services/link.js"; import server from "../services/server.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; import TabAwareWidget from "./tab_aware_widget.js"; import options from "../services/options.js"; @@ -109,12 +109,12 @@ export default class SimilarNotesWidget extends TabAwareWidget { const noteIds = similarNotes.flatMap(note => note.notePath); - await treeCache.getNotes(noteIds, true); // preload all at once + await froca.getNotes(noteIds, true); // preload all at once const $list = $('
    '); for (const similarNote of similarNotes) { - const note = await treeCache.getNote(similarNote.noteId, true); + const note = await froca.getNote(similarNote.noteId, true); if (!note) { continue; diff --git a/src/public/app/widgets/tab_aware_widget.js b/src/public/app/widgets/tab_aware_widget.js index 44b20cc43..c9fa7b2e5 100644 --- a/src/public/app/widgets/tab_aware_widget.js +++ b/src/public/app/widgets/tab_aware_widget.js @@ -92,7 +92,7 @@ export default class TabAwareWidget extends BasicWidget { } } - async treeCacheReloadedEvent() { + async frocaReloadedEvent() { await this.refresh(); } diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 64e0b0c29..b4dbabd30 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -3,7 +3,7 @@ import contextMenu from "../services/context_menu.js"; import utils from "../services/utils.js"; import keyboardActionService from "../services/keyboard_actions.js"; import appContext from "../services/app_context.js"; -import treeCache from "../services/tree_cache.js"; +import froca from "../services/tree_cache.js"; /*! * Draggabilly v2.3.0 @@ -635,7 +635,7 @@ export default class TabRowWidget extends BasicWidget { const tabContext = appContext.tabManager.getTabContextById(this.getTabId($tab)); if (tabContext) { - const hoistedNote = treeCache.getNoteFromCache(tabContext.hoistedNoteId); + const hoistedNote = froca.getNoteFromCache(tabContext.hoistedNoteId); if (hoistedNote) { $tab.find('.note-tab-icon') @@ -680,7 +680,7 @@ export default class TabRowWidget extends BasicWidget { } } - treeCacheReloadedEvent() { + frocaReloadedEvent() { for (const tabContext of appContext.tabManager.tabContexts) { const $tab = this.getTabById(tabContext.tabId); diff --git a/src/public/app/widgets/type_property_widgets/search_definition.js b/src/public/app/widgets/type_property_widgets/search_definition.js index 4b061741c..96f8c1182 100644 --- a/src/public/app/widgets/type_property_widgets/search_definition.js +++ b/src/public/app/widgets/type_property_widgets/search_definition.js @@ -1,6 +1,6 @@ import server from "../../services/server.js"; import TabAwareWidget from "../tab_aware_widget.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import ws from "../../services/ws.js"; import toastService from "../../services/toast.js"; @@ -265,7 +265,7 @@ export default class SearchDefinitionWidget extends TabAwareWidget { async refreshResultsCommand() { try { - await treeCache.loadSearchNote(this.noteId); + await froca.loadSearchNote(this.noteId); } catch (e) { toastService.showError(e.message); diff --git a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js index d4ca8c4c8..66c8482d7 100644 --- a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js +++ b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js @@ -1,6 +1,6 @@ import TypeWidget from "./type_widget.js"; import appContext from "../../services/app_context.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import linkService from "../../services/link.js"; import noteContentRenderer from "../../services/note_content_renderer.js"; @@ -47,7 +47,7 @@ export default class AbstractTextTypeWidget extends TypeWidget { } async loadIncludedNote(noteId, $el) { - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); if (note) { const $link = await linkService.createNoteLink(note.noteId, { diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index 876272eb7..53a762597 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -3,7 +3,7 @@ import noteAutocompleteService from '../../services/note_autocomplete.js'; import mimeTypesService from '../../services/mime_types.js'; import utils from "../../services/utils.js"; import keyboardActionService from "../../services/keyboard_actions.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import treeService from "../../services/tree.js"; import noteCreateService from "../../services/note_create.js"; import AbstractTextTypeWidget from "./abstract_text_type_widget.js"; @@ -129,7 +129,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } async doRefresh(note) { - const noteComplement = await treeCache.getNoteComplement(note.noteId); + const noteComplement = await froca.getNoteComplement(note.noteId); await this.spacedUpdate.allowUpdateWithoutChange(() => { this.textEditor.setData(noteComplement.content || ""); @@ -265,7 +265,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } async addImage(noteId) { - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); this.textEditor.model.change( writer => { const src = `api/images/${note.noteId}/${note.title}`; diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js index f5a132e66..7eb4f1a49 100644 --- a/src/public/app/widgets/type_widgets/read_only_text.js +++ b/src/public/app/widgets/type_widgets/read_only_text.js @@ -1,4 +1,4 @@ -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; import AbstractTextTypeWidget from "./abstract_text_type_widget.js"; import treeService from "../../services/tree.js"; import libraryLoader from "../../services/library_loader.js"; @@ -83,7 +83,7 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { // (see https://github.com/zadam/trilium/issues/1590 for example of such conflict) await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); - const noteComplement = await treeCache.getNoteComplement(note.noteId); + const noteComplement = await froca.getNoteComplement(note.noteId); this.$content.html(noteComplement.content); diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.js index 0c94cf844..1e6afa59a 100644 --- a/src/public/app/widgets/type_widgets/relation_map.js +++ b/src/public/app/widgets/type_widgets/relation_map.js @@ -7,7 +7,7 @@ import attributeAutocompleteService from "../../services/attribute_autocomplete. import TypeWidget from "./type_widget.js"; import appContext from "../../services/app_context.js"; import utils from "../../services/utils.js"; -import treeCache from "../../services/tree_cache.js"; +import froca from "../../services/tree_cache.js"; const uniDirectionalOverlays = [ [ "Arrow", { @@ -532,7 +532,7 @@ export default class RelationMapTypeWidget extends TypeWidget { linkService.goToLink(e); }); - const note = await treeCache.getNote(noteId); + const note = await froca.getNote(noteId); const $noteBox = $("
    ") .addClass("note-box") diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index bcf32ac25..9ac9b2b19 100644 --- a/src/services/note_cache/entities/note.js +++ b/src/services/note_cache/entities/note.js @@ -235,7 +235,7 @@ class Note { this.ancestorCache = null; } - invalidateSubtreeCaches(path = []) { + invalidateSubfrocas(path = []) { if (path.includes(this.noteId)) { return; } @@ -247,7 +247,7 @@ class Note { } for (const childNote of this.children) { - childNote.invalidateSubtreeCaches(path); + childNote.invalidateSubfrocas(path); } for (const targetRelation of this.targetRelations) { @@ -255,7 +255,7 @@ class Note { const note = targetRelation.note; if (note) { - note.invalidateSubtreeCaches(path); + note.invalidateSubfrocas(path); } } } diff --git a/src/services/note_cache/note_cache_loader.js b/src/services/note_cache/note_cache_loader.js index 07c41de22..4c51b8883 100644 --- a/src/services/note_cache/note_cache_loader.js +++ b/src/services/note_cache/note_cache_loader.js @@ -66,7 +66,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED childNote.parentBranches = childNote.parentBranches.filter(branch => branch.branchId !== branchId); if (childNote.parents.length > 0) { - childNote.invalidateSubtreeCaches(); + childNote.invalidateSubfrocas(); } } @@ -105,7 +105,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED if (note && attr) { // first invalidate and only then remove the attribute (otherwise invalidation wouldn't be complete) if (attr.isAffectingSubtree || note.isTemplate) { - note.invalidateSubtreeCaches(); + note.invalidateSubfrocas(); } else { note.invalidateThisCache(); } @@ -147,7 +147,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED if (note) { if (attr.isAffectingSubtree || note.isTemplate) { - note.invalidateSubtreeCaches(); + note.invalidateSubfrocas(); } else { note.invalidateThisCache(); diff --git a/src/services/script.js b/src/services/script.js index 6f34b9eaf..9f495f20c 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -5,7 +5,7 @@ const log = require('./log'); async function executeNote(note, apiParams) { if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable) { - log.info(`Cannot execute note ${note.noteId}`); + log.info(`Cannot execute note ${note.noteId} "${note.title}", note must be of type "Code: JS frontend"`); return; }