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
fix: duplicate colors and indices
thecodrr3e3b4220e7bd
diff --git a/packages/core/database/indexed-collection.js b/packages/core/database/indexed-collection.jsindex 2ad0fcf5e..6d03d62dc 100644--- a/packages/core/database/indexed-collection.js+++ b/packages/core/database/indexed-collection.js@@ -16,7 +16,7 @@ export default class IndexedCollection {async addItem(item) {if (!item.id) throw new Error("The item must contain the id field.");- const exists = await this.exists(item.id);+ const exists = this.exists(item.id);if (!exists) item.dateCreated = item.dateCreated || Date.now();await this.updateItem(item);if (!exists) {diff --git a/packages/core/database/indexer.js b/packages/core/database/indexer.jsindex 5623b4657..0b55fe326 100644--- a/packages/core/database/indexer.js+++ b/packages/core/database/indexer.js@@ -11,20 +11,22 @@ export default class Indexer extends Storage {this.indices = (await this.read(this.type, true)) || [];}- async exists(key) {+ exists(key) {return this.indices.includes(key);}async index(key) {- this.indices[this.indices.length] = key;+ if (this.exists(key)) return;+ this.indices.push(key);await this.write(this.type, this.indices);}- async getIndices() {+ getIndices() {return this.indices;}async deindex(key) {+ if (!this.exists(key)) return;this.indices.splice(this.indices.indexOf(key), 1);await this.write(this.type, this.indices);}diff --git a/packages/core/database/migrator.js b/packages/core/database/migrator.jsindex 5bfbadc99..d739cdadf 100644--- a/packages/core/database/migrator.js+++ b/packages/core/database/migrator.js@@ -6,25 +6,26 @@ class Migrator {await Promise.all(collections.map(async (collection) => {if (!collection.index || !collection.dbCollection) return;+ for (var i = 0; i < collection.index.length; ++i) {+ let id = collection.index[i];+ let item = get(id);+ if (!item) {+ continue;+ }- await Promise.all(- collection.index.map(async (id) => {- let item = get(id);- if (!item) return;+ if (item.deleted && !item.type) {+ await collection.dbCollection?._collection?.addItem(item);+ continue;+ }+ const migrate = migrations[version][item.type || collection.type];+ if (migrate) item = migrate(item);- if (item.deleted && !item.type)- return await collection.dbCollection?._collection?.addItem(item);-- const migrate = migrations[version][item.type || collection.type];- if (migrate) item = migrate(item);-- if (!!collection.dbCollection.merge) {- await collection.dbCollection.merge(item);- } else {- await collection.dbCollection.add(item);- }- })- );+ if (!!collection.dbCollection.merge) {+ await collection.dbCollection.merge(item);+ } else {+ await collection.dbCollection.add(item);+ }+ }}));return true;