mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
feat: improve indexing performance
This commit is contained in:
@@ -17,16 +17,18 @@ export default class Lookup {
|
|||||||
notes(notes, query) {
|
notes(notes, query) {
|
||||||
return sm.union(
|
return sm.union(
|
||||||
this._db.content._collection.search.search(query, {
|
this._db.content._collection.search.search(query, {
|
||||||
|
shouldMap: true,
|
||||||
map: (elem) => {
|
map: (elem) => {
|
||||||
return notes.find((note) => note.contentId === elem);
|
return notes.find((note) => note.contentId === elem);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
this._db.notes._collection.search.search(query)
|
this._db.notes._collection.search.search(query, { shouldMap: true })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
notebooks(array, query) {
|
notebooks(array, query) {
|
||||||
return this._db.notebooks._collection.search.search(query, {
|
return this._db.notebooks._collection.search.search(query, {
|
||||||
|
shouldMap: true,
|
||||||
map: (elem) => {
|
map: (elem) => {
|
||||||
return array.find((nb) => nb.id === elem);
|
return array.find((nb) => nb.id === elem);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,16 +7,18 @@ import IndexedCollection from "./indexed-collection";
|
|||||||
|
|
||||||
export default class CachedCollection extends IndexedCollection {
|
export default class CachedCollection extends IndexedCollection {
|
||||||
async init() {
|
async init() {
|
||||||
const index = new PersistentCachedMap(`${this.type}Index`, this.storage);
|
const store = new PersistentCachedMap(this.storeKey, this.storage);
|
||||||
const store = new PersistentCachedMap(`${this.type}Store`, this.storage);
|
|
||||||
await index.init();
|
|
||||||
await store.init();
|
await store.init();
|
||||||
this.search = new HyperSearch({
|
this.search = new HyperSearch({
|
||||||
schema: getSchema(this.type),
|
schema: getSchema(this.type),
|
||||||
tokenizer: "forward",
|
tokenizer: "forward",
|
||||||
index,
|
|
||||||
store,
|
store,
|
||||||
|
onIndexUpdated: async () => {
|
||||||
|
await this.storage.write(this.indexKey, this.search.indexer.export());
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
const index = await this.storage.read(this.indexKey);
|
||||||
|
this.search.indexer.import(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
exists(id) {
|
exists(id) {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export default class IndexedCollection {
|
|||||||
constructor(storage, type) {
|
constructor(storage, type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
|
this.indexKey = `${this.type}Index`;
|
||||||
|
this.storeKey = `${this.type}Store`;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@@ -21,16 +23,18 @@ export default class IndexedCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
const index = new PersistentCachedMap(`${this.type}Index`, this.storage);
|
|
||||||
const store = new PersistentMap(`${this.type}Store`, this.storage);
|
const store = new PersistentMap(`${this.type}Store`, this.storage);
|
||||||
await index.init();
|
|
||||||
await store.init();
|
await store.init();
|
||||||
this.search = new HyperSearch({
|
this.search = new HyperSearch({
|
||||||
schema: getSchema(this.type),
|
schema: getSchema(this.type),
|
||||||
tokenizer: "forward",
|
tokenizer: "forward",
|
||||||
index,
|
|
||||||
store,
|
store,
|
||||||
|
onIndexUpdated: async () => {
|
||||||
|
await this.storage.write(this.indexKey, this.search.indexer.export());
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
const index = await this.storage.read(this.indexKey);
|
||||||
|
this.search.indexer.import(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addItem(item) {
|
async addItem(item) {
|
||||||
|
|||||||
@@ -2704,8 +2704,8 @@ http-signature@~1.2.0:
|
|||||||
sshpk "^1.7.0"
|
sshpk "^1.7.0"
|
||||||
|
|
||||||
"hypersearch@https://github.com/streetwriters/hypersearch":
|
"hypersearch@https://github.com/streetwriters/hypersearch":
|
||||||
version "0.1.0"
|
version "0.2.2"
|
||||||
resolved "https://github.com/streetwriters/hypersearch#fa5d2b8435c1b7bca4b5f8059054da848fe1631f"
|
resolved "https://github.com/streetwriters/hypersearch#951e68c2f4dfd12325094791b8d430d6f1c4128e"
|
||||||
|
|
||||||
iconv-lite@0.4.24:
|
iconv-lite@0.4.24:
|
||||||
version "0.4.24"
|
version "0.4.24"
|
||||||
|
|||||||
Reference in New Issue
Block a user