refactor: slight performance improvements

This commit is contained in:
thecodrr
2019-12-01 00:13:59 +05:00
parent 66209c7a4b
commit 66ba9c4f9f
2 changed files with 10 additions and 2 deletions

View File

@@ -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
); );
} }

View File

@@ -0,0 +1,7 @@
export function extractValues(obj) {
const t = [];
for (var key in obj) {
t[t.length] = obj[key];
}
return t;
}