Skip to content

Commit

Permalink
Add debug log for SynchronizedCollection in CI runs for database writ…
Browse files Browse the repository at this point in the history
…es with outdated data (#376)

* 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>
  • Loading branch information
sebbi08 and jkoenig134 authored Dec 20, 2024
1 parent 78674f2 commit 8a079be
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/transport/src/modules/sync/SynchronizedCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8a079be

Please sign in to comment.