Skip to content

Build your personal knowledge base with Trilium Notes

note title widget and protected session entering fixes

zadam8b5536ee3a16
diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.js
index 100df55e14..29f6e4e9a5 100644
--- a/src/public/app/services/protected_session.js
+++ b/src/public/app/services/protected_session.js
@@ -31,6 +31,15 @@ function enterProtectedSession() {
return dfd.promise();
}
+async function reloadData() {
+ const allNoteIds = Object.keys(treeCache.notes);
+
+ await treeCache.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);
+}
+
async function setupProtectedSession(password) {
const response = await enterProtectedSessionOnServer(password);
@@ -42,7 +51,7 @@ async function setupProtectedSession(password) {
protectedSessionHolder.setProtectedSessionId(response.protectedSessionId);
protectedSessionHolder.touchProtectedSession();
- await treeCache.loadInitialTree();
+ await reloadData();
await appContext.triggerEvent('treeCacheReloaded');
diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js
index baf7350b36..4b18b7fa8b 100644
--- a/src/public/app/services/tree_cache.js
+++ b/src/public/app/services/tree_cache.js
@@ -20,6 +20,8 @@ class TreeCache {
async loadInitialTree() {
const resp = await server.get('tree');
+ await this.loadParents(resp, false);
+
// clear the cache only directly before adding new content which is important for e.g. switching to protected session
/** @type {Object.<string, NoteShort>} */
@@ -34,22 +36,22 @@ class TreeCache {
/** @type {Object.<string, Promise<NoteComplement>>} */
this.noteComplementPromises = {};
- await this.loadParents(resp);
this.addResp(resp);
}
- async loadParents(resp) {
+ async loadParents(resp, additiveLoad) {
const noteIds = new Set(resp.notes.map(note => note.noteId));
const missingNoteIds = [];
+ const existingNotes = additiveLoad ? this.notes : {};
for (const branch of resp.branches) {
- if (!(branch.parentNoteId in this.notes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
+ if (!(branch.parentNoteId in existingNotes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
missingNoteIds.push(branch.parentNoteId);
}
}
for (const attr of resp.attributes) {
- if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in this.notes) && !noteIds.has(attr.value)) {
+ if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in existingNotes) && !noteIds.has(attr.value)) {
missingNoteIds.push(attr.value);
}
}
@@ -61,7 +63,7 @@ class TreeCache {
resp.branches = resp.branches.concat(newResp.branches);
resp.attributes = resp.attributes.concat(newResp.attributes);
- await this.loadParents(resp);
+ await this.loadParents(resp, additiveLoad);
}
}
@@ -154,7 +156,7 @@ class TreeCache {
const resp = await server.post('tree/load', { noteIds });
- await this.loadParents(resp);
+ await this.loadParents(resp, true);
this.addResp(resp);
for (const note of resp.notes) {
diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js
index f44421049e..576dd5b810 100644
--- a/src/public/app/widgets/note_title.js
+++ b/src/public/app/widgets/note_title.js
@@ -57,6 +57,10 @@ export default class NoteTitleWidget extends TabAwareWidget {
this.$noteTitle.prop("readonly", note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable());
+ this.setProtectedStatus(note);
+ }
+
+ setProtectedStatus(note) {
this.$noteTitle.toggleClass("protected", !!note.isProtected);
}
@@ -88,7 +92,8 @@ export default class NoteTitleWidget extends TabAwareWidget {
entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) {
- this.refresh();
+ // not updating the title specifically since the synced title might be older than what the user is currently typing
+ this.setProtectedStatus(this.note);
}
}
diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js
index 455ff4166d..8e897d7fdd 100644
--- a/src/public/app/widgets/note_tree.js
+++ b/src/public/app/widgets/note_tree.js
@@ -486,7 +486,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return true;
}
else {
- const childBranches = await this.getChildBranches(note);
+ const childBranches = this.getChildBranches(note);
return childBranches.length > 0;
}
@@ -497,7 +497,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
const noteList = [];
- for (const branch of await this.getChildBranches(parentNote)) {
+ for (const branch of this.getChildBranches(parentNote)) {
const node = await this.prepareNode(branch);
noteList.push(node);
@@ -506,7 +506,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return noteList;
}
- async getChildBranches(parentNote) {
+ getChildBranches(parentNote) {
let childBranches = parentNote.getChildBranches();
if (!childBranches) {
@@ -521,20 +521,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
childBranches = childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
}
- if (this.hideArchivedNotes) {
- const filteredBranches = [];
-
- for (const childBranch of childBranches) {
- const childNote = await childBranch.getNote();
-
- if (!childNote.hasLabel('archived')) {
- filteredBranches.push(childBranch);
- }
- }
-
- childBranches = filteredBranches;
- }
-
return childBranches;
}
diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js
index a5898c3972..ce8b50f057 100644
--- a/src/services/consistency_checks.js
+++ b/src/services/consistency_checks.js
@@ -617,6 +617,9 @@ class ConsistencyChecks {
await this.findSyncRowsIssues();
+ // root branch should always be expanded
+ await sql.execute("UPDATE branches SET isExpanded = 1 WHERE branchId = 'root'");
+
if (this.unrecoveredConsistencyErrors) {
// we run this only if basic checks passed since this assumes basic data consistency