diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-24 17:10:33 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-24 17:10:33 +0100 |
commit | 38f05ed5552329fe79743ed4caace8313442d3ed (patch) | |
tree | 983610863fcf03b39198332c95aa1ce5d8f03230 /framework/domain/maillistmodel.cpp | |
parent | dec32c8e1fc2ee6eece1330300f6690389a0898d (diff) | |
download | kube-38f05ed5552329fe79743ed4caace8313442d3ed.tar.gz kube-38f05ed5552329fe79743ed4caace8313442d3ed.zip |
Compress synchronization requests
Diffstat (limited to 'framework/domain/maillistmodel.cpp')
-rw-r--r-- | framework/domain/maillistmodel.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index 58a6b384..c6897990 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp | |||
@@ -27,6 +27,8 @@ MailListModel::MailListModel(QObject *parent) | |||
27 | { | 27 | { |
28 | setDynamicSortFilter(true); | 28 | setDynamicSortFilter(true); |
29 | sort(0, Qt::DescendingOrder); | 29 | sort(0, Qt::DescendingOrder); |
30 | connect(&mFetchTimer, &QTimer::timeout, this, &MailListModel::fetch); | ||
31 | mFetchTimer.setSingleShot(true); | ||
30 | } | 32 | } |
31 | 33 | ||
32 | MailListModel::~MailListModel() | 34 | MailListModel::~MailListModel() |
@@ -71,12 +73,29 @@ static QString join(const QList<Sink::ApplicationDomain::Mail::Contact> &contact | |||
71 | return list.join(", "); | 73 | return list.join(", "); |
72 | } | 74 | } |
73 | 75 | ||
74 | void MailListModel::fetchMail(Sink::ApplicationDomain::Mail::Ptr mail) const | 76 | void MailListModel::fetchMail(Sink::ApplicationDomain::Mail::Ptr mail) |
75 | { | 77 | { |
76 | if (mail && !mail->getFullPayloadAvailable() && !mFetchedMails.contains(mail->identifier())) { | 78 | if (mail && !mail->getFullPayloadAvailable() && !mFetchedMails.contains(mail->identifier())) { |
77 | qDebug() << "Fetching mail: " << mail->identifier() << mail->getSubject(); | 79 | qDebug() << "Fetching mail: " << mail->identifier() << mail->getSubject(); |
78 | mFetchedMails.insert(mail->identifier()); | 80 | mFetchedMails.insert(mail->identifier()); |
79 | Sink::Store::synchronize(Sink::SyncScope{*mail}).exec(); | 81 | mMailsToFetch << *mail; |
82 | //TODO it would be nicer if Sink could just transparently merge synchronization requeusts. | ||
83 | if (!mFetchTimer.isActive()) { | ||
84 | mFetchTimer.start(50); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | void MailListModel::fetch() | ||
90 | { | ||
91 | if (!mMailsToFetch.isEmpty()) { | ||
92 | auto first = mMailsToFetch.first(); | ||
93 | auto scope = Sink::SyncScope{first}; | ||
94 | for (const auto &m : mMailsToFetch) { | ||
95 | scope.filter(m.identifier()); | ||
96 | } | ||
97 | Sink::Store::synchronize(scope).exec(); | ||
98 | mMailsToFetch.clear(); | ||
80 | } | 99 | } |
81 | } | 100 | } |
82 | 101 | ||
@@ -113,7 +132,7 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const | |||
113 | return QVariant::fromValue(mail); | 132 | return QVariant::fromValue(mail); |
114 | case MimeMessage: | 133 | case MimeMessage: |
115 | if (mFetchMails) { | 134 | if (mFetchMails) { |
116 | fetchMail(mail); | 135 | const_cast<MailListModel*>(this)->fetchMail(mail); |
117 | } | 136 | } |
118 | return mail->getMimeMessage(); | 137 | return mail->getMimeMessage(); |
119 | case ThreadSize: | 138 | case ThreadSize: |