From da4b74e593f1b1262e83824cc499bd855f1b4e3e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 26 Jun 2018 10:24:58 +0200 Subject: Avoid overwriting local changes with remote modifications. The case we ran into is the following: * Fetching the full payload and marking all messages of a thread as read happens simultaneously. * The local modification to mark as read gets immediately overwritten when the full payload arrives. * Eventually the modification gets replayed to the server though (and the reversal isn't because coming from the source), so on next sync the situation fixes itself. To be able to improve this we try to protect local modifications in that properties that have been modified since baseRevision (which currently isn't, but should be equal to the last to the server replayed revision) are not overwritten. This conflict resolution strategy thus always prefers local modifications. baseRevision is currently set to the current maximum revision of the store at the time when the resource creates the modification. --- common/pipeline.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'common/pipeline.cpp') diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 4afe9f3..cbdc91d 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -258,7 +258,19 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) return KAsync::error(0); } - auto newEntity = d->entityStore.applyDiff(bufferType, current, diff, deletions); + //We avoid overwriting local changes that haven't been played back yet with remote modifications + QSet excludeProperties; + if (!replayToSource) { //We assume this means the change is coming from the source already + d->entityStore.readRevisions(bufferType, diff.identifier(), baseRevision, [&] (const QByteArray &uid, qint64 revision, const Sink::EntityBuffer &entity) { + if (entity.metadataBuffer()) { + if (auto metadata = GetMetadata(entity.metadataBuffer())) { + excludeProperties += BufferUtils::fromVector(*metadata->modifiedProperties()).toSet(); + } + } + }); + } + + auto newEntity = d->entityStore.applyDiff(bufferType, current, diff, deletions, excludeProperties); bool isMove = false; if (modifyEntity->targetResource()) { -- cgit v1.2.3