mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
refactor: slight performance improvements
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import Storage from "../helpers/storage";
|
import Storage from "../helpers/storage";
|
||||||
import fuzzysearch from "fuzzysearch";
|
import fuzzysearch from "fuzzysearch";
|
||||||
import ff from "fast-filter";
|
import ff from "fast-filter";
|
||||||
|
import { extractValues } from "../utils";
|
||||||
|
|
||||||
const KEYS = {
|
const KEYS = {
|
||||||
notes: "notes"
|
notes: "notes"
|
||||||
@@ -18,7 +19,7 @@ class Database {
|
|||||||
async getNotes() {
|
async getNotes() {
|
||||||
//update our cache
|
//update our cache
|
||||||
this.notes = (await this.storage.read(KEYS.notes)) || {};
|
this.notes = (await this.storage.read(KEYS.notes)) || {};
|
||||||
return Object.values(this.notes);
|
return extractValues(this.notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +90,7 @@ class Database {
|
|||||||
if (!notes) return;
|
if (!notes) return;
|
||||||
return ff(
|
return ff(
|
||||||
notes,
|
notes,
|
||||||
v => fuzzysearch(query, v.title) || fuzzysearch(query, v.content.text),
|
v => fuzzysearch(query, v.title + " " + v.content.text),
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
7
packages/core/utils/index.js
Normal file
7
packages/core/utils/index.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function extractValues(obj) {
|
||||||
|
const t = [];
|
||||||
|
for (var key in obj) {
|
||||||
|
t[t.length] = obj[key];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user