diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-07 16:26:52 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-10 10:40:01 +0200 |
commit | 615fc9df81555ce5a2b16747640beba43e109ef4 (patch) | |
tree | e22c130d87adcb43f8769c4d4ca254f60b7b6ba1 /common/facade.h | |
parent | f689ad1021a7805f6f8b6a81f534b4cb9ca91f51 (diff) | |
download | sink-615fc9df81555ce5a2b16747640beba43e109ef4.tar.gz sink-615fc9df81555ce5a2b16747640beba43e109ef4.zip |
Always get the latest revision directly from storage
We can just as well read the latest available revision from storage.
Diffstat (limited to 'common/facade.h')
-rw-r--r-- | common/facade.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/common/facade.h b/common/facade.h index dab1578..5ed3bde 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -44,7 +44,7 @@ class QueryRunner : public QObject | |||
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | public: | 46 | public: |
47 | typedef std::function<KAsync::Job<qint64>(qint64 oldRevision, qint64 newRevision)> QueryFunction; | 47 | typedef std::function<KAsync::Job<qint64>(qint64 oldRevision)> QueryFunction; |
48 | 48 | ||
49 | QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {}; | 49 | QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {}; |
50 | /** | 50 | /** |
@@ -53,10 +53,11 @@ public: | |||
53 | KAsync::Job<void> run(qint64 newRevision = 0) | 53 | KAsync::Job<void> run(qint64 newRevision = 0) |
54 | { | 54 | { |
55 | //TODO: JOBAPI: that last empty .then should not be necessary | 55 | //TODO: JOBAPI: that last empty .then should not be necessary |
56 | //TODO: remove newRevision | ||
56 | if (mLatestRevision == newRevision && mLatestRevision > 0) { | 57 | if (mLatestRevision == newRevision && mLatestRevision > 0) { |
57 | return KAsync::null<void>(); | 58 | return KAsync::null<void>(); |
58 | } | 59 | } |
59 | return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) { | 60 | return queryFunction(mLatestRevision).then<void, qint64>([this](qint64 revision) { |
60 | mLatestRevision = revision + 1; | 61 | mLatestRevision = revision + 1; |
61 | }).then<void>([](){}); | 62 | }).then<void>([](){}); |
62 | } | 63 | } |
@@ -160,9 +161,9 @@ public: | |||
160 | { | 161 | { |
161 | auto runner = QSharedPointer<QueryRunner>::create(query); | 162 | auto runner = QSharedPointer<QueryRunner>::create(query); |
162 | QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider; | 163 | QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider; |
163 | runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> KAsync::Job<qint64> { | 164 | runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision) -> KAsync::Job<qint64> { |
164 | return KAsync::start<qint64>([this, weakResultProvider, query, oldRevision, newRevision](KAsync::Future<qint64> &future) { | 165 | return KAsync::start<qint64>([this, weakResultProvider, query, oldRevision](KAsync::Future<qint64> &future) { |
165 | Trace() << "Executing query " << oldRevision << newRevision; | 166 | Trace() << "Executing query " << oldRevision; |
166 | auto resultProvider = weakResultProvider.toStrongRef(); | 167 | auto resultProvider = weakResultProvider.toStrongRef(); |
167 | if (!resultProvider) { | 168 | if (!resultProvider) { |
168 | Warning() << "Tried executing query after result provider is already gone"; | 169 | Warning() << "Tried executing query after result provider is already gone"; |
@@ -170,7 +171,7 @@ public: | |||
170 | future.setFinished(); | 171 | future.setFinished(); |
171 | return; | 172 | return; |
172 | } | 173 | } |
173 | load(query, resultProvider, oldRevision, newRevision).template then<void, qint64>([&future](qint64 queriedRevision) { | 174 | load(query, resultProvider, oldRevision).template then<void, qint64>([&future](qint64 queriedRevision) { |
174 | //TODO set revision in result provider? | 175 | //TODO set revision in result provider? |
175 | //TODO update all existing results with new revision | 176 | //TODO update all existing results with new revision |
176 | future.setValue(queriedRevision); | 177 | future.setValue(queriedRevision); |
@@ -213,11 +214,10 @@ protected: | |||
213 | } | 214 | } |
214 | 215 | ||
215 | private: | 216 | private: |
216 | virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) | 217 | virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision) |
217 | { | 218 | { |
218 | return KAsync::start<qint64>([=]() -> qint64 { | 219 | return KAsync::start<qint64>([=]() -> qint64 { |
219 | mStorage->read(query, qMakePair(oldRevision, newRevision), resultProvider); | 220 | return mStorage->read(query, oldRevision, resultProvider); |
220 | return newRevision; | ||
221 | }); | 221 | }); |
222 | } | 222 | } |
223 | 223 | ||