diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-07 14:56:03 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-07 14:56:03 +0100 |
commit | 3506c78afcfcf63d74d1b57b53518ea27dae2f8c (patch) | |
tree | da98a2f754e870d47316d8bf8b85dc84f4d62517 /examples | |
parent | 4ecb10d3b1294d03578c28467c0f3759b3496e0b (diff) | |
download | sink-3506c78afcfcf63d74d1b57b53518ea27dae2f8c.tar.gz sink-3506c78afcfcf63d74d1b57b53518ea27dae2f8c.zip |
Merge synchronization requests for individual mails of the same folder.
We use this frequently when loading conversations, so this results in a
significant preformance improvement.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 09f57d5..fff4dc7 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -393,6 +393,44 @@ public: | |||
393 | return list; | 393 | return list; |
394 | } | 394 | } |
395 | 395 | ||
396 | QByteArray getFolderFromLocalId(const QByteArray &id) | ||
397 | { | ||
398 | auto mailRemoteId = syncStore().resolveLocalId(ApplicationDomain::getTypeName<ApplicationDomain::Mail>(), id); | ||
399 | return folderIdFromMailRid(mailRemoteId); | ||
400 | } | ||
401 | |||
402 | void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue) Q_DECL_OVERRIDE | ||
403 | { | ||
404 | auto isIndividualMailSync = [](const Synchronizer::SyncRequest &request) { | ||
405 | if (request.requestType == SyncRequest::Synchronization) { | ||
406 | const auto query = request.query; | ||
407 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { | ||
408 | return !query.ids().isEmpty(); | ||
409 | } | ||
410 | } | ||
411 | return false; | ||
412 | |||
413 | }; | ||
414 | |||
415 | if (isIndividualMailSync(request)) { | ||
416 | auto newId = request.query.ids().first(); | ||
417 | auto requestFolder = getFolderFromLocalId(newId); | ||
418 | for (auto &r : queue) { | ||
419 | if (isIndividualMailSync(r)) { | ||
420 | auto queueFolder = getFolderFromLocalId(r.query.ids().first()); | ||
421 | if (requestFolder == queueFolder) { | ||
422 | //Merge | ||
423 | r.query.filter(newId); | ||
424 | SinkTrace() << "Merging request " << request.query; | ||
425 | SinkTrace() << " to " << r.query; | ||
426 | return; | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | } | ||
431 | queue << request; | ||
432 | } | ||
433 | |||
396 | KAsync::Job<void> login(QSharedPointer<ImapServerProxy> imap) | 434 | KAsync::Job<void> login(QSharedPointer<ImapServerProxy> imap) |
397 | { | 435 | { |
398 | SinkTrace() << "Connecting to:" << mServer << mPort; | 436 | SinkTrace() << "Connecting to:" << mServer << mPort; |