summaryrefslogtreecommitdiffstats
path: root/common/sourcewriteback.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/sourcewriteback.cpp')
-rw-r--r--common/sourcewriteback.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/common/sourcewriteback.cpp b/common/sourcewriteback.cpp
index 1ef20d2..1c07577 100644
--- a/common/sourcewriteback.cpp
+++ b/common/sourcewriteback.cpp
@@ -54,8 +54,7 @@ RemoteIdMap &SourceWriteBack::syncStore()
54 54
55KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) 55KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value)
56{ 56{
57 mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); 57 Trace() << "Replaying" << type << key;
58 mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite);
59 58
60 Sink::EntityBuffer buffer(value); 59 Sink::EntityBuffer buffer(value);
61 const Sink::Entity &entity = buffer.entity(); 60 const Sink::Entity &entity = buffer.entity();
@@ -65,7 +64,14 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
65 Trace() << "Change is coming from the source"; 64 Trace() << "Change is coming from the source";
66 return KAsync::null<void>(); 65 return KAsync::null<void>();
67 } 66 }
68 const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; 67 Q_ASSERT(!mSyncStore);
68 Q_ASSERT(!mEntityStore);
69 Q_ASSERT(!mTransaction);
70 Q_ASSERT(!mSyncTransaction);
71 mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly);
72 mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite);
73
74 // const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1;
69 const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; 75 const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation;
70 const auto uid = Sink::Storage::uidFromKey(key); 76 const auto uid = Sink::Storage::uidFromKey(key);
71 QByteArray oldRemoteId; 77 QByteArray oldRemoteId;
@@ -84,32 +90,38 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
84 job = replay(mail, operation, oldRemoteId); 90 job = replay(mail, operation, oldRemoteId);
85 } 91 }
86 92
87 return job.then<void, QByteArray>([this, operation, type, uid](const QByteArray &remoteId) { 93 return job.then<void, QByteArray>([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) {
88 Trace() << "Replayed change with remote id: " << remoteId;
89 if (operation == Sink::Operation_Creation) { 94 if (operation == Sink::Operation_Creation) {
95 Trace() << "Replayed creation with remote id: " << remoteId;
90 if (remoteId.isEmpty()) { 96 if (remoteId.isEmpty()) {
91 Warning() << "Returned an empty remoteId from the creation"; 97 Warning() << "Returned an empty remoteId from the creation";
92 } else { 98 } else {
93 syncStore().recordRemoteId(type, uid, remoteId); 99 syncStore().recordRemoteId(type, uid, remoteId);
94 } 100 }
95 } else if (operation == Sink::Operation_Modification) { 101 } else if (operation == Sink::Operation_Modification) {
102 Trace() << "Replayed modification with remote id: " << remoteId;
96 if (remoteId.isEmpty()) { 103 if (remoteId.isEmpty()) {
97 Warning() << "Returned an empty remoteId from the creation"; 104 Warning() << "Returned an empty remoteId from the creation";
98 } else { 105 } else {
99 syncStore().updateRemoteId(type, uid, remoteId); 106 syncStore().updateRemoteId(type, uid, remoteId);
100 } 107 }
101 } else if (operation == Sink::Operation_Removal) { 108 } else if (operation == Sink::Operation_Removal) {
102 syncStore().removeRemoteId(type, uid, remoteId); 109 Trace() << "Replayed removal with remote id: " << oldRemoteId;
110 syncStore().removeRemoteId(type, uid, oldRemoteId);
103 } else { 111 } else {
104 Warning() << "Unkown operation" << operation; 112 ErrorMsg() << "Unkown operation" << operation;
105 } 113 }
106 114
115 mSyncStore.clear();
116 mEntityStore.clear();
107 mTransaction.abort(); 117 mTransaction.abort();
108 mSyncTransaction.commit(); 118 mSyncTransaction.commit();
119 }, [this](int errorCode, const QString &errorMessage) {
120 Warning() << "Failed to replay change: " << errorMessage;
109 mSyncStore.clear(); 121 mSyncStore.clear();
110 mEntityStore.clear(); 122 mEntityStore.clear();
111 }, [](int errorCode, const QString &errorMessage) { 123 mTransaction.abort();
112 Warning() << "Failed to replay change: " << errorMessage; 124 mSyncTransaction.commit();
113 }); 125 });
114} 126}
115 127