Skip to content

Commit

Permalink
make sure to preserve modification of ThingWriteModel to be available…
Browse files Browse the repository at this point in the history
… for subsequent processing of patch update

Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch.io>
  • Loading branch information
dguggemos committed Sep 1, 2022
1 parent 845c7ba commit 2fdbcb8
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -199,6 +199,7 @@ public String toString() {
}

private Optional<MongoWriteModel> computeDiff(final ThingWriteModel lastWriteModel, final int maxWireVersion) {
final ThingWriteModel thingWriteModel;
final WriteModel<BsonDocument> mongoWriteModel;
final boolean isPatchUpdate1;

Expand All @@ -218,13 +219,15 @@ private Optional<MongoWriteModel> computeDiff(final ThingWriteModel lastWriteMod
PATCH_SKIP_COUNT.increment();
return Optional.empty();
}
final var filter = asPatchUpdate(lastWriteModel.getMetadata().getThingRevision()).getFilter();
thingWriteModel = asPatchUpdate(lastWriteModel.getMetadata().getThingRevision());
final var filter = thingWriteModel.getFilter();
mongoWriteModel = new UpdateOneModel<>(filter, aggregationPipeline);
LOGGER.debug("Using incremental update <{}>", mongoWriteModel.getClass().getSimpleName());
LOGGER.trace("Using incremental update <{}>", mongoWriteModel);
PATCH_UPDATE_COUNT.increment();
isPatchUpdate1 = true;
} else {
thingWriteModel = this;
mongoWriteModel = this.toMongo();
LOGGER.debug("Using replacement because diff is bigger or nonexistent: <{}>",
mongoWriteModel.getClass().getSimpleName());
Expand All @@ -235,7 +238,7 @@ private Optional<MongoWriteModel> computeDiff(final ThingWriteModel lastWriteMod
FULL_UPDATE_COUNT.increment();
isPatchUpdate1 = false;
}
return Optional.of(MongoWriteModel.of(this, mongoWriteModel, isPatchUpdate1));
return Optional.of(MongoWriteModel.of(thingWriteModel, mongoWriteModel, isPatchUpdate1));
}

private Optional<BsonDiff> tryComputeDiff(final BsonDocument minuend, final BsonDocument subtrahend,
Expand Down

0 comments on commit 2fdbcb8

Please sign in to comment.