Skip to content

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

Revert "feat: improve indexing performance"

thecodrr20a3d1ab20a6
diff --git a/packages/core/api/lookup.js b/packages/core/api/lookup.js
index b164fa5ee..08b8f2de9 100644
--- a/packages/core/api/lookup.js
+++ b/packages/core/api/lookup.js
@@ -17,18 +17,16 @@ export default class Lookup {
notes(notes, query) {
return sm.union(
this._db.content._collection.search.search(query, {
- shouldMap: true,
map: (elem) => {
return notes.find((note) => note.contentId === elem);
},
}),
- this._db.notes._collection.search.search(query, { shouldMap: true })
+ this._db.notes._collection.search.search(query)
);
}
notebooks(array, query) {
return this._db.notebooks._collection.search.search(query, {
- shouldMap: true,
map: (elem) => {
return array.find((nb) => nb.id === elem);
},
diff --git a/packages/core/database/cached-collection.js b/packages/core/database/cached-collection.js
index 32e69fa77..93467595c 100644
--- a/packages/core/database/cached-collection.js
+++ b/packages/core/database/cached-collection.js
@@ -7,18 +7,16 @@ import IndexedCollection from "./indexed-collection";
export default class CachedCollection extends IndexedCollection {
async init() {
- const store = new PersistentCachedMap(this.storeKey, this.storage);
+ const index = new PersistentCachedMap(`${this.type}Index`, this.storage);
+ const store = new PersistentCachedMap(`${this.type}Store`, this.storage);
+ await index.init();
await store.init();
this.search = new HyperSearch({
schema: getSchema(this.type),
tokenizer: "forward",
+ index,
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) {
diff --git a/packages/core/database/indexed-collection.js b/packages/core/database/indexed-collection.js
index e544dbaa4..25d769a20 100644
--- a/packages/core/database/indexed-collection.js
+++ b/packages/core/database/indexed-collection.js
@@ -14,8 +14,6 @@ export default class IndexedCollection {
constructor(storage, type) {
this.type = type;
this.storage = storage;
- this.indexKey = `${this.type}Index`;
- this.storeKey = `${this.type}Store`;
}
clear() {
@@ -23,18 +21,16 @@ export default class IndexedCollection {
}
async init() {
+ const index = new PersistentCachedMap(`${this.type}Index`, this.storage);
const store = new PersistentMap(`${this.type}Store`, this.storage);
+ await index.init();
await store.init();
this.search = new HyperSearch({
schema: getSchema(this.type),
tokenizer: "forward",
+ index,
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) {
diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock
index 44bebc9ce..36d7eaead 100644
--- a/packages/core/yarn.lock
+++ b/packages/core/yarn.lock
@@ -2704,8 +2704,8 @@ http-signature@~1.2.0:
sshpk "^1.7.0"
"hypersearch@https://github.com/streetwriters/hypersearch":
- version "0.2.2"
- resolved "https://github.com/streetwriters/hypersearch#951e68c2f4dfd12325094791b8d430d6f1c4128e"
+ version "0.1.0"
+ resolved "https://github.com/streetwriters/hypersearch#fa5d2b8435c1b7bca4b5f8059054da848fe1631f"
version "0.4.24"