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
core: generate deterministic ids for relations to avoid duplicates
Abdullah Atta38a34857db68
diff --git a/packages/core/collections/relations.js b/packages/core/collections/relations.jsindex ca4d31110..e273d74a1 100644--- a/packages/core/collections/relations.js+++ b/packages/core/collections/relations.js@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import getId from "../utils/id";+import { makeId } from "../utils/id";import Collection from "./collection";/**@@ -57,7 +57,7 @@ export default class Relations extends Collection {return;const relation = {- id: getId(),+ id: generateId(from, to),type: "relation",dateCreated: Date.now(),dateModified: Date.now(),@@ -146,3 +146,13 @@ export default class Relations extends Collection {function compareItemReference(a, b) {return a.id === b.id && a.type === b.type;}++/**+ * Generate deterministic constant id from `a` & `b` item reference.+ * @param {ItemReference} a+ * @param {ItemReference} b+ */+function generateId(a, b) {+ const str = `${a.id}${b.id}${a.type}${b.type}`;+ return makeId(str);+}