From e10e18e63ac102c407f132e8d5cc20152d1420db Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 7 Oct 2021 07:46:13 +0200 Subject: [PATCH] added optimized version for single label searching + noteset cache fix --- src/becca/becca.js | 4 ++-- src/services/attributes.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/becca/becca.js b/src/becca/becca.js index e99eb1f9e..c800ca8a7 100644 --- a/src/becca/becca.js +++ b/src/becca/becca.js @@ -154,10 +154,10 @@ class Becca { } } - this.allNoteSet = new NoteSet(allNotes); + this.allNoteSetCache = new NoteSet(allNotes); } - return this.allNoteSet; + return this.allNoteSetCache; } } diff --git a/src/services/attributes.js b/src/services/attributes.js index b646af7f1..2d60d40c8 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -71,9 +71,16 @@ function getNotesWithLabel(name, value) { // TODO: should be in search service function getNoteWithLabel(name, value) { - const notes = getNotesWithLabel(name, value); + // optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes + const attrs = becca.findAttributes('label', name); - return notes.length > 0 ? notes[0] : null; + for (const attr of attrs) { + if (attr.value === value) { + return attr.getNote(); + } + } + + return null; } function createLabel(noteId, name, value = "") {