diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-20 01:12:23 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-20 01:12:23 +0200 |
commit | b10ca588b7a8a5e3bec22b9e683b4a4dbd5bc889 (patch) | |
tree | d9dffc7c8ef7caac35934fc38c410281911ac265 | |
parent | ea4d0708e63b7dc7ee0b1cb150f1e09da1f52046 (diff) | |
download | sink-b10ca588b7a8a5e3bec22b9e683b4a4dbd5bc889.tar.gz sink-b10ca588b7a8a5e3bec22b9e683b4a4dbd5bc889.zip |
Don't create a transaction for every appended message.
We create now only one transaction for the whole sync which is also not
ideal.
-rw-r--r-- | common/genericresource.cpp | 2 | ||||
-rw-r--r-- | common/synchronizer.cpp | 5 | ||||
-rw-r--r-- | 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<Synchronizer> &sync | |||
323 | mSynchronizer = synchronizer; | 323 | mSynchronizer = synchronizer; |
324 | mSynchronizer->setup([this](int commandId, const QByteArray &data) { | 324 | mSynchronizer->setup([this](int commandId, const QByteArray &data) { |
325 | enqueueCommand(mSynchronizerQueue, commandId, data); | 325 | enqueueCommand(mSynchronizerQueue, commandId, data); |
326 | }); | 326 | }, mSynchronizerQueue); |
327 | } | 327 | } |
328 | 328 | ||
329 | void GenericResource::setupChangereplay(const QSharedPointer<ChangeReplay> &changeReplay) | 329 | void GenericResource::setupChangereplay(const QSharedPointer<ChangeReplay> &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() | |||
45 | 45 | ||
46 | } | 46 | } |
47 | 47 | ||
48 | void Synchronizer::setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback) | 48 | void Synchronizer::setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &mq) |
49 | { | 49 | { |
50 | mEnqueue = enqueueCommandCallback; | 50 | mEnqueue = enqueueCommandCallback; |
51 | mMessageQueue = &mq; | ||
51 | } | 52 | } |
52 | 53 | ||
53 | void Synchronizer::enqueueCommand(int commandId, const QByteArray &data) | 54 | void Synchronizer::enqueueCommand(int commandId, const QByteArray &data) |
@@ -239,9 +240,11 @@ void Synchronizer::modify(const DomainType &entity) | |||
239 | KAsync::Job<void> Synchronizer::synchronize() | 240 | KAsync::Job<void> Synchronizer::synchronize() |
240 | { | 241 | { |
241 | Trace() << "Synchronizing"; | 242 | Trace() << "Synchronizing"; |
243 | mMessageQueue->startTransaction(); | ||
242 | return synchronizeWithSource().then<void>([this]() { | 244 | return synchronizeWithSource().then<void>([this]() { |
243 | mSyncStore.clear(); | 245 | mSyncStore.clear(); |
244 | mEntityStore.clear(); | 246 | mEntityStore.clear(); |
247 | mMessageQueue->commit(); | ||
245 | }); | 248 | }); |
246 | } | 249 | } |
247 | 250 | ||
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 @@ | |||
24 | #include <Async/Async> | 24 | #include <Async/Async> |
25 | #include <domainadaptor.h> | 25 | #include <domainadaptor.h> |
26 | #include <query.h> | 26 | #include <query.h> |
27 | 27 | #include <messagequeue.h> | |
28 | #include "storage.h" | 28 | #include <storage.h> |
29 | 29 | ||
30 | namespace Sink { | 30 | namespace Sink { |
31 | class EntityStore; | 31 | class EntityStore; |
@@ -40,7 +40,7 @@ public: | |||
40 | Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); | 40 | Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); |
41 | virtual ~Synchronizer(); | 41 | virtual ~Synchronizer(); |
42 | 42 | ||
43 | void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback); | 43 | void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &messageQueue); |
44 | KAsync::Job<void> synchronize(); | 44 | KAsync::Job<void> synchronize(); |
45 | 45 | ||
46 | //Read only access to main storage | 46 | //Read only access to main storage |
@@ -105,6 +105,7 @@ private: | |||
105 | Sink::Storage::Transaction mTransaction; | 105 | Sink::Storage::Transaction mTransaction; |
106 | Sink::Storage::Transaction mSyncTransaction; | 106 | Sink::Storage::Transaction mSyncTransaction; |
107 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; | 107 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; |
108 | MessageQueue *mMessageQueue; | ||
108 | }; | 109 | }; |
109 | 110 | ||
110 | } | 111 | } |