Skip to content

Build your personal knowledge base with Trilium Notes

improved note list pager for many pages

zadam60e2026850d2
diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js
index 77ca2f2ccf..ba23260c1e 100644
--- a/src/public/app/services/note_list_renderer.js
+++ b/src/public/app/services/note_list_renderer.js
@@ -239,18 +239,29 @@ class NoteListRenderer {
$pager.toggle(pageCount > 1);
+ let lastPrinted;
+
for (let i = 1; i <= pageCount; i++) {
- $pager.append(
- i === this.page
- ? $('<span>').text(i).css('text-decoration', 'underline').css('font-weight', "bold")
- : $('<a href="javascript:">')
- .text(i)
- .on('click', () => {
- this.page = i;
- this.renderList();
- }),
- " &nbsp; "
- );
+ if (pageCount < 20 || i <= 5 || pageCount - i <= 5 || Math.abs(this.page - i) <= 2) {
+ lastPrinted = true;
+
+ $pager.append(
+ i === this.page
+ ? $('<span>').text(i).css('text-decoration', 'underline').css('font-weight', "bold")
+ : $('<a href="javascript:">')
+ .text(i)
+ .on('click', () => {
+ this.page = i;
+ this.renderList();
+ }),
+ " &nbsp; "
+ );
+ }
+ else if (lastPrinted) {
+ $pager.append("... &nbsp; ");
+
+ lastPrinted = false;
+ }
}
}
diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js
index 066705bf44..ae70634c11 100644
--- a/src/routes/api/tree.js
+++ b/src/routes/api/tree.js
@@ -97,9 +97,6 @@ function getNotesAndBranchesAndAttributes(noteIds) {
});
}
- branches.sort((a, b) => a.notePosition - b.notePosition < 0 ? -1 : 1);
- attributes.sort((a, b) => a.position - b.position < 0 ? -1 : 1);
-
return {
branches,
notes,
diff --git a/src/services/note_cache/entities/attribute.js b/src/services/note_cache/entities/attribute.js
index 1dc2c61068..769e33c8ad 100644
--- a/src/services/note_cache/entities/attribute.js
+++ b/src/services/note_cache/entities/attribute.js
@@ -13,7 +13,7 @@ class Attribute {
/** @param {string} */
this.type = row.type;
/** @param {string} */
- this.name = row.name.toLowerCase();
+ this.name = row.name;
/** @param {int} */
this.position = row.position;
diff --git a/src/services/note_cache/entities/branch.js b/src/services/note_cache/entities/branch.js
index 002dc8f944..49dbb1b78a 100644
--- a/src/services/note_cache/entities/branch.js
+++ b/src/services/note_cache/entities/branch.js
@@ -17,7 +17,7 @@ class Branch {
/** @param {int} */
this.notePosition = row.notePosition;
/** @param {boolean} */
- this.isExpanded = row.isExpanded;
+ this.isExpanded = !!row.isExpanded;
if (this.branchId === 'root') {
return;
diff --git a/src/services/note_cache/note_cache.js b/src/services/note_cache/note_cache.js
index 812050afd2..f6c943a3fb 100644
--- a/src/services/note_cache/note_cache.js
+++ b/src/services/note_cache/note_cache.js
@@ -14,7 +14,7 @@ class NoteCache {
this.childParentToBranch = {};
/** @type {Object.<String, Attribute>} */
this.attributes = [];
- /** @type {Object.<String, Attribute[]>} Points from attribute type-name to list of attributes them */
+ /** @type {Object.<String, Attribute[]>} Points from attribute type-name to list of attributes */
this.attributeIndex = {};
this.loaded = false;
@@ -22,7 +22,7 @@ class NoteCache {
/** @return {Attribute[]} */
findAttributes(type, name) {
- return this.attributeIndex[`${type}-${name}`] || [];
+ return this.attributeIndex[`${type}-${name.toLowerCase()}`] || [];
}
/** @return {Attribute[]} */
diff --git a/src/services/note_cache/note_cache_loader.js b/src/services/note_cache/note_cache_loader.js
index dc57b2927c..4fbe379c61 100644
--- a/src/services/note_cache/note_cache_loader.js
+++ b/src/services/note_cache/note_cache_loader.js
@@ -14,6 +14,7 @@ sqlInit.dbReady.then(() => {
});
function load() {
+ const start = Date.now();
noteCache.reset();
for (const row of sql.iterateRows(`SELECT noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes WHERE isDeleted = 0`, [])) {
@@ -29,6 +30,8 @@ function load() {
}
noteCache.loaded = true;
+
+ log.info(`Note cache load took ${Date.now() - start}ms`);
}
eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED], ({entityName, entity}) => {