From 8a079becc2ee0f3691ad2b79a71301d7e5478dcd Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Fri, 20 Dec 2024 13:12:55 +0100 Subject: [PATCH] Add debug log for SynchronizedCollection in CI runs for database writes with outdated data (#376) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: add log in debug mode for db write with wrong data * chore: remove blub * chore: only run this in ci * chore: remove ci test * chore: make it browser save * Update packages/transport/src/modules/sync/SynchronizedCollection.ts Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com> * chore: remove debug config in synccollection --------- Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com> --- .../src/modules/sync/SynchronizedCollection.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/transport/src/modules/sync/SynchronizedCollection.ts b/packages/transport/src/modules/sync/SynchronizedCollection.ts index a63479887..252d921eb 100644 --- a/packages/transport/src/modules/sync/SynchronizedCollection.ts +++ b/packages/transport/src/modules/sync/SynchronizedCollection.ts @@ -87,6 +87,23 @@ export class SynchronizedCollection implements IDatabaseCollection { const newObjectJson = newObject.toJSON(); + if (typeof globalThis.process === "object" && globalThis.process.env.CI) { + const oldDocUpdated = Serializable.fromUnknown(await this.parent.read(newObject.id.toString())); + + const readDiff = jsonpatch.compare(oldDocUpdated.toJSON(), oldObject.toJSON()); + if (readDiff.length > 0) { + // eslint-disable-next-line no-console + console.error(` +The data that is currently updated got modified between it initial reading and this update. +This will lead to an data loss and inconsistency. +Here is the diff of the data: +${JSON.stringify(readDiff, null, 2)} + +Stack: +${new Error().stack}`); + } + } + if (!this.datawalletModifications) { return await this.parent.update(oldDoc, newObject); }