summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/synchronizer.cpp10
-rw-r--r--common/synchronizer.h2
-rw-r--r--examples/imapresource/imapresource.cpp4
-rw-r--r--examples/maildirresource/maildirresource.cpp4
4 files changed, 7 insertions, 13 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index cf50b0b..1374d00 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -240,24 +240,26 @@ void Synchronizer::modify(const DomainType &entity)
240KAsync::Job<void> Synchronizer::synchronize() 240KAsync::Job<void> Synchronizer::synchronize()
241{ 241{
242 Trace() << "Synchronizing"; 242 Trace() << "Synchronizing";
243 mSyncInProgress = true;
243 mMessageQueue->startTransaction(); 244 mMessageQueue->startTransaction();
244 return synchronizeWithSource().then<void>([this]() { 245 return synchronizeWithSource().then<void>([this]() {
245 mSyncStore.clear(); 246 mSyncStore.clear();
246 mEntityStore.clear(); 247 mEntityStore.clear();
247 mMessageQueue->commit(); 248 mMessageQueue->commit();
249 mSyncInProgress = false;
248 }); 250 });
249} 251}
250 252
251void Synchronizer::commit() 253void Synchronizer::commit()
252{ 254{
255 mMessageQueue->commit();
253 mTransaction.abort(); 256 mTransaction.abort();
254 mEntityStore.clear(); 257 mEntityStore.clear();
255}
256
257void Synchronizer::commitSync()
258{
259 mSyncTransaction.commit(); 258 mSyncTransaction.commit();
260 mSyncStore.clear(); 259 mSyncStore.clear();
260 if (mSyncInProgress) {
261 mMessageQueue->startTransaction();
262 }
261} 263}
262 264
263Sink::Storage::Transaction &Synchronizer::transaction() 265Sink::Storage::Transaction &Synchronizer::transaction()
diff --git a/common/synchronizer.h b/common/synchronizer.h
index 9c0e2e2..81d4f27 100644
--- a/common/synchronizer.h
+++ b/common/synchronizer.h
@@ -50,7 +50,6 @@ public:
50 RemoteIdMap &syncStore(); 50 RemoteIdMap &syncStore();
51 51
52 void commit(); 52 void commit();
53 void commitSync();
54 Sink::Storage::Transaction &transaction(); 53 Sink::Storage::Transaction &transaction();
55 Sink::Storage::Transaction &syncTransaction(); 54 Sink::Storage::Transaction &syncTransaction();
56 55
@@ -106,6 +105,7 @@ private:
106 Sink::Storage::Transaction mSyncTransaction; 105 Sink::Storage::Transaction mSyncTransaction;
107 std::function<void(int commandId, const QByteArray &data)> mEnqueue; 106 std::function<void(int commandId, const QByteArray &data)> mEnqueue;
108 MessageQueue *mMessageQueue; 107 MessageQueue *mMessageQueue;
108 bool mSyncInProgress;
109}; 109};
110 110
111} 111}
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index f9168e4..b5d224c 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -251,7 +251,6 @@ public:
251 251
252 createOrModify(bufferType, remoteId, mail); 252 createOrModify(bufferType, remoteId, mail);
253 } 253 }
254 commitSync();
255 const auto elapsed = time->elapsed(); 254 const auto elapsed = time->elapsed();
256 Log() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 255 Log() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
257 } 256 }
@@ -310,7 +309,6 @@ public:
310 auto folderFuture = imap.fetchFolders([this, &imap, &folderList](const QVector<Folder> &folders) { 309 auto folderFuture = imap.fetchFolders([this, &imap, &folderList](const QVector<Folder> &folders) {
311 synchronizeFolders(folders); 310 synchronizeFolders(folders);
312 commit(); 311 commit();
313 commitSync();
314 folderList << folders; 312 folderList << folders;
315 313
316 }).exec(); 314 }).exec();
@@ -332,7 +330,6 @@ public:
332 } 330 }
333 synchronizeMails(folder.normalizedPath(), messages); 331 synchronizeMails(folder.normalizedPath(), messages);
334 commit(); 332 commit();
335 commitSync();
336 }).exec(); 333 }).exec();
337 messagesFuture.waitForFinished(); 334 messagesFuture.waitForFinished();
338 if (messagesFuture.errorCode()) { 335 if (messagesFuture.errorCode()) {
@@ -342,7 +339,6 @@ public:
342 //Remove what there is to remove 339 //Remove what there is to remove
343 synchronizeRemovals(folder.normalizedPath(), uids); 340 synchronizeRemovals(folder.normalizedPath(), uids);
344 commit(); 341 commit();
345 commitSync();
346 Trace() << "Folder synchronized: " << folder.normalizedPath(); 342 Trace() << "Folder synchronized: " << folder.normalizedPath();
347 } 343 }
348 344
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 5fa7084..23e25c4 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -393,7 +393,6 @@ public:
393 393
394 createOrModify(bufferType, remoteId, mail); 394 createOrModify(bufferType, remoteId, mail);
395 } 395 }
396 commitSync();
397 const auto elapsed = time->elapsed(); 396 const auto elapsed = time->elapsed();
398 Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 397 Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
399 } 398 }
@@ -409,12 +408,10 @@ public:
409 synchronizeFolders(); 408 synchronizeFolders();
410 //The next sync needs the folders available 409 //The next sync needs the folders available
411 commit(); 410 commit();
412 commitSync();
413 for (const auto &folder : listAvailableFolders()) { 411 for (const auto &folder : listAvailableFolders()) {
414 synchronizeMails(folder); 412 synchronizeMails(folder);
415 //Don't let the transaction grow too much 413 //Don't let the transaction grow too much
416 commit(); 414 commit();
417 commitSync();
418 } 415 }
419 Log() << "Done Synchronizing"; 416 Log() << "Done Synchronizing";
420 return KAsync::null<void>(); 417 return KAsync::null<void>();
@@ -515,7 +512,6 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh
515 auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder", QByteArrayList() << "drafts"); 512 auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder", QByteArrayList() << "drafts");
516 auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); 513 auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId);
517 synchronizer->commit(); 514 synchronizer->commit();
518 synchronizer->commitSync();
519 515
520 folderUpdater->mDraftsFolder = draftsFolderLocalId; 516 folderUpdater->mDraftsFolder = draftsFolderLocalId;
521 folderUpdater->mResourceInstanceIdentifier = mResourceInstanceIdentifier; 517 folderUpdater->mResourceInstanceIdentifier = mResourceInstanceIdentifier;