Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

perf: use single loop for notes filtering

thecodrrd76709fe1e97
diff --git a/packages/core/api/lookup.js b/packages/core/api/lookup.js
index 85e926db8..cb5657e3b 100644
--- a/packages/core/api/lookup.js
+++ b/packages/core/api/lookup.js
@@ -15,19 +15,18 @@ export default class Lookup {
this._db = db;
}
- async notes(array, query) {
- const textIds = array.map(v => v.content.text);
- const textArray = await this._db.text.multi(textIds);
- const filteredText = tfun.filter(text => fuzzysearch(query, text.data))(
- textArray
- );
- const filteredByText = filteredText.map(text =>
- array.find(note => note.id === text.noteId)
- );
- const filteredByTitle = tfun.filter(note => fuzzysearch(query, note.title))(
- array
- );
- return set.union(filteredByText, filteredByTitle);
+ notes(notes, query) {
+ return new Promise(resolve => {
+ const results = [];
+ let index = 0,
+ max = notes.length;
+ notes.forEach(async note => {
+ const text = await this._db.text.get(note.content.text);
+ const title = note.title;
+ if (fuzzysearch(query, text + title)) results.push(note);
+ if (++index >= max) return resolve(results);
+ });
+ });
}
notebooks(array, query) {