From 6b09016f5d9119729265211db6cc91f991fc3e28 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 30 Aug 2016 00:48:01 +0200 Subject: Don' create new entities on flag change. --- common/synchronizer.cpp | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 15a06e7..8de45a9 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -143,36 +143,45 @@ void Synchronizer::scanForRemovals(const QByteArray &bufferType, const std::func }); } +void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) +{ + auto mainDatabase = Storage::mainDatabase(transaction(), bufferType); + const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); + auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); + Q_ASSERT(adaptorFactory); + qint64 retrievedRevision = 0; + if (auto current = EntityReaderUtils::getLatest(mainDatabase, sinkId, *adaptorFactory, retrievedRevision)) { + bool changed = false; + for (const auto &property : entity.changedProperties()) { + if (entity.getProperty(property) != current->getProperty(property)) { + SinkTrace() << "Property changed " << sinkId << property; + changed = true; + } + } + if (changed) { + SinkTrace() << "Found a modified entity: " << remoteId; + modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory, + [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); + } + } else { + SinkWarning() << "Failed to get current entity"; + } +} + void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) { SinkTrace() << "Create or modify" << bufferType << remoteId; auto mainDatabase = Storage::mainDatabase(transaction(), bufferType); const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); const auto found = mainDatabase.contains(sinkId); - auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); - Q_ASSERT(adaptorFactory); if (!found) { SinkTrace() << "Found a new entity: " << remoteId; + auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); + Q_ASSERT(adaptorFactory); createEntity( sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); }); } else { // modification - qint64 retrievedRevision = 0; - if (auto current = EntityReaderUtils::getLatest(mainDatabase, sinkId, *adaptorFactory, retrievedRevision)) { - bool changed = false; - for (const auto &property : entity.changedProperties()) { - if (entity.getProperty(property) != current->getProperty(property)) { - SinkTrace() << "Property changed " << sinkId << property; - changed = true; - } - } - if (changed) { - SinkTrace() << "Found a modified entity: " << remoteId; - modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory, - [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); - } - } else { - SinkWarning() << "Failed to get current entity"; - } + modify(bufferType, remoteId, entity); } } -- cgit v1.2.3