A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: remove unnecessary db transaction logic
thecodrr0d8b7559707e
diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.jsindex fd20438d7..018f567a7 100644--- a/packages/core/collections/notebooks.js+++ b/packages/core/collections/notebooks.js@@ -78,9 +78,7 @@ export default class Notebooks extends Collection {for (let id of ids) {let notebook = this.notebook(id);if (!notebook) continue;- await this._collection.transaction(() =>- notebook.topics.delete(...notebook.data.topics)- );+ await notebook.topics.delete(...notebook.data.topics);await this._collection.removeItem(id);await this._db.trash.add(notebook.data);}diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.jsindex db09a437e..9958032a1 100644--- a/packages/core/collections/notes.js+++ b/packages/core/collections/notes.js@@ -192,12 +192,10 @@ export default class Notes extends Collection {let item = this.note(id);if (!item) continue;if (item.notebook && item.notebook.id && item.notebook.topic) {- await this._collection.transaction(() =>- this._db.notebooks- .notebook(item.notebook.id)- .topics.topic(item.notebook.topic)- .delete(id)- );+ await this._db.notebooks+ .notebook(item.notebook.id)+ .topics.topic(item.notebook.topic)+ .delete(id);}for (let tag of item.tags) {await this._db.tags.remove(tag, id);diff --git a/packages/core/collections/topics.js b/packages/core/collections/topics.jsindex cba32f675..e81fb8eae 100644--- a/packages/core/collections/topics.js+++ b/packages/core/collections/topics.js@@ -98,7 +98,7 @@ export default class Topics {if (!topic) continue;let index = topicIds.findIndex((id) => topic.id === id);let t = this.topic(topic);- await t.transaction(() => t.delete(...topic.notes), false);+ await t.delete(...topic.notes);if (index > -1) {allTopics.splice(i, 1);}diff --git a/packages/core/database/cached-collection.js b/packages/core/database/cached-collection.jsindex c3e63cc3a..9ecef7df9 100644--- a/packages/core/database/cached-collection.js+++ b/packages/core/database/cached-collection.js@@ -6,7 +6,6 @@ export default class CachedCollection {constructor(context, type) {this.map = new Map();this.indexer = new Indexer(context, type);- this.transactionOpen = false;}async init() {@@ -20,17 +19,7 @@ export default class CachedCollection {await this.indexer.clear();}- /**- *- * @param {Promise} ops- */- transaction(ops) {- this.transactionOpen = true;- return ops().then(() => Promise.resolve((this.transactionOpen = false)));- }-async addItem(item) {- if (this.transactionOpen) return;if (!item.id) throw new Error("The item must contain the id field.");let exists = this.map.has(item.id);@@ -44,7 +33,6 @@ export default class CachedCollection {}async updateItem(item) {- if (this.transactionOpen) return;if (!item.id) throw new Error("The item must contain the id field.");// if item is newly synced, remote will be true.item.dateEdited = item.remote ? item.dateEdited : Date.now();diff --git a/packages/core/models/topic.js b/packages/core/models/topic.jsindex 50a7d13f4..efe796c7e 100644--- a/packages/core/models/topic.js+++ b/packages/core/models/topic.js@@ -9,22 +9,12 @@ export default class Topic {this._topic = topic;this._db = db;this._notebookId = notebookId;- this._transactionOpen = false;}get totalNotes() {return this._topic.totalNotes;}- transaction(ops, saveAfter = true) {- this._transactionOpen = true;- ops().then(() => {- this._transactionOpen = false;- });- if (!saveAfter) return this;- return this._save();- }-has(noteId) {return this._topic.notes.findIndex((n) => n === noteId) > -1;}@@ -71,7 +61,6 @@ export default class Topic {}async _save(topic) {- if (this._transactionOpen) return this;await this._db.notebooks.notebook(this._notebookId).topics.add(topic);return this;}diff --git a/packages/core/package.json b/packages/core/package.jsonindex b1bbc4c0e..6768f4c83 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -23,6 +23,7 @@"dependencies": {"fast-sort": "^2.0.1","fuzzysearch": "^1.0.3",+ "hypersearch": "https://github.com/streetwriters/hypersearch","jshashes": "^1.0.8","no-internet": "^1.5.2","qclone": "^1.0.4",diff --git a/packages/core/yarn.lock b/packages/core/yarn.lockindex 741a94d9a..fb40e8cf9 100644--- a/packages/core/yarn.lock+++ b/packages/core/yarn.lock@@ -2703,6 +2703,10 @@ http-signature@~1.2.0:jsprim "^1.2.2"sshpk "^1.7.0"+"hypersearch@https://github.com/streetwriters/hypersearch":+ version "0.0.1"+ resolved "https://github.com/streetwriters/hypersearch#bbeac8ad63c3f70e94dfd05b0f00f44ecc989a19"+version "0.4.24"resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"