From b10ca588b7a8a5e3bec22b9e683b4a4dbd5bc889 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 20 Jun 2016 01:12:23 +0200 Subject: Don't create a transaction for every appended message. We create now only one transaction for the whole sync which is also not ideal. --- common/genericresource.cpp | 2 +- common/synchronizer.cpp | 5 ++++- common/synchronizer.h | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 87b6da1..d43eff7 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -323,7 +323,7 @@ void GenericResource::setupSynchronizer(const QSharedPointer &sync mSynchronizer = synchronizer; mSynchronizer->setup([this](int commandId, const QByteArray &data) { enqueueCommand(mSynchronizerQueue, commandId, data); - }); + }, mSynchronizerQueue); } void GenericResource::setupChangereplay(const QSharedPointer &changeReplay) diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index ee7a7ba..cf50b0b 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -45,9 +45,10 @@ Synchronizer::~Synchronizer() } -void Synchronizer::setup(const std::function &enqueueCommandCallback) +void Synchronizer::setup(const std::function &enqueueCommandCallback, MessageQueue &mq) { mEnqueue = enqueueCommandCallback; + mMessageQueue = &mq; } void Synchronizer::enqueueCommand(int commandId, const QByteArray &data) @@ -239,9 +240,11 @@ void Synchronizer::modify(const DomainType &entity) KAsync::Job Synchronizer::synchronize() { Trace() << "Synchronizing"; + mMessageQueue->startTransaction(); return synchronizeWithSource().then([this]() { mSyncStore.clear(); mEntityStore.clear(); + mMessageQueue->commit(); }); } diff --git a/common/synchronizer.h b/common/synchronizer.h index 6f98f35..9c0e2e2 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h @@ -24,8 +24,8 @@ #include #include #include - -#include "storage.h" +#include +#include namespace Sink { class EntityStore; @@ -40,7 +40,7 @@ public: Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); virtual ~Synchronizer(); - void setup(const std::function &enqueueCommandCallback); + void setup(const std::function &enqueueCommandCallback, MessageQueue &messageQueue); KAsync::Job synchronize(); //Read only access to main storage @@ -105,6 +105,7 @@ private: Sink::Storage::Transaction mTransaction; Sink::Storage::Transaction mSyncTransaction; std::function mEnqueue; + MessageQueue *mMessageQueue; }; } -- cgit v1.2.3