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 | |
parent | dec32c8e1fc2ee6eece1330300f6690389a0898d (diff) | |
download | kube-38f05ed5552329fe79743ed4caace8313442d3ed.tar.gz kube-38f05ed5552329fe79743ed4caace8313442d3ed.zip |
Compress synchronization requests
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/maillistmodel.cpp | 25 | ||||
-rw-r--r-- | framework/domain/maillistmodel.h | 10 |
2 files changed, 30 insertions, 5 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: |
diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index af079a1b..1fd0ef5e 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <QSortFilterProxyModel> | 25 | #include <QSortFilterProxyModel> |
26 | #include <QSharedPointer> | 26 | #include <QSharedPointer> |
27 | #include <QStringList> | 27 | #include <QStringList> |
28 | #include <QTimer> | ||
28 | 29 | ||
29 | class MailListModel : public QSortFilterProxyModel | 30 | class MailListModel : public QSortFilterProxyModel |
30 | { | 31 | { |
@@ -69,11 +70,16 @@ public: | |||
69 | void setMail(const QVariant &mail); | 70 | void setMail(const QVariant &mail); |
70 | QVariant mail() const; | 71 | QVariant mail() const; |
71 | 72 | ||
73 | private slots: | ||
74 | void fetch(); | ||
75 | |||
72 | private: | 76 | private: |
73 | void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail) const; | 77 | void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail); |
74 | 78 | ||
75 | QSharedPointer<QAbstractItemModel> m_model; | 79 | QSharedPointer<QAbstractItemModel> m_model; |
76 | bool mFetchMails = false; | 80 | bool mFetchMails = false; |
77 | mutable QSet<QByteArray> mFetchedMails; | 81 | QSet<QByteArray> mFetchedMails; |
82 | QList<Sink::ApplicationDomain::Mail> mMailsToFetch; | ||
78 | QByteArray mCurrentQueryItem; | 83 | QByteArray mCurrentQueryItem; |
84 | QTimer mFetchTimer; | ||
79 | }; | 85 | }; |