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 | |
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.
-rw-r--r-- | common/entitystorage.cpp | 3 | ||||
-rw-r--r-- | common/entitystorage.h | 9 | ||||
-rw-r--r-- | common/facade.h | 18 | ||||
-rw-r--r-- | tests/genericfacadetest.cpp | 5 |
4 files changed, 20 insertions, 15 deletions
diff --git a/common/entitystorage.cpp b/common/entitystorage.cpp index 60d58ad..c60135e 100644 --- a/common/entitystorage.cpp +++ b/common/entitystorage.cpp | |||
@@ -121,8 +121,9 @@ ResultSet EntityStorageBase::loadInitialResultSet(const Akonadi2::Query &query, | |||
121 | return resultSet; | 121 | return resultSet; |
122 | } | 122 | } |
123 | 123 | ||
124 | ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision) | 124 | ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision) |
125 | { | 125 | { |
126 | const qint64 topRevision = Akonadi2::Storage::maxRevision(transaction); | ||
126 | QSet<QByteArray> remainingFilters = query.propertyFilter.keys().toSet(); | 127 | QSet<QByteArray> remainingFilters = query.propertyFilter.keys().toSet(); |
127 | ResultSet resultSet; | 128 | ResultSet resultSet; |
128 | const bool initialQuery = (baseRevision == 0); | 129 | const bool initialQuery = (baseRevision == 0); |
diff --git a/common/entitystorage.h b/common/entitystorage.h index f1d7f84..68b9e46 100644 --- a/common/entitystorage.h +++ b/common/entitystorage.h | |||
@@ -54,7 +54,7 @@ protected: | |||
54 | * TODO: Resources should be able to customize this for cases where an entity is not the same as a single buffer. | 54 | * TODO: Resources should be able to customize this for cases where an entity is not the same as a single buffer. |
55 | */ | 55 | */ |
56 | void readEntity(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)> &resultCallback); | 56 | void readEntity(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)> &resultCallback); |
57 | ResultSet getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision); | 57 | ResultSet getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision); |
58 | 58 | ||
59 | protected: | 59 | protected: |
60 | QByteArray mResourceInstanceIdentifier; | 60 | QByteArray mResourceInstanceIdentifier; |
@@ -99,7 +99,7 @@ protected: | |||
99 | 99 | ||
100 | public: | 100 | public: |
101 | 101 | ||
102 | virtual void read(const Akonadi2::Query &query, const QPair<qint64, qint64> &revisionRange, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) | 102 | virtual qint64 read(const Akonadi2::Query &query, qint64 baseRevision, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) |
103 | { | 103 | { |
104 | Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier); | 104 | Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier); |
105 | storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) { | 105 | storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) { |
@@ -108,10 +108,10 @@ public: | |||
108 | 108 | ||
109 | auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); | 109 | auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); |
110 | 110 | ||
111 | Log() << "Querying" << revisionRange.first << revisionRange.second; | 111 | Log() << "Querying" << baseRevision; |
112 | //TODO fallback in case the old revision is no longer available to clear + redo complete initial scan | 112 | //TODO fallback in case the old revision is no longer available to clear + redo complete initial scan |
113 | // | 113 | // |
114 | auto resultSet = getResultSet(query, transaction, revisionRange.first, revisionRange.second); | 114 | auto resultSet = getResultSet(query, transaction, baseRevision); |
115 | while(resultSet.next([this, resultProvider](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool { | 115 | while(resultSet.next([this, resultProvider](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool { |
116 | switch (operation) { | 116 | switch (operation) { |
117 | case Akonadi2::Operation_Creation: | 117 | case Akonadi2::Operation_Creation: |
@@ -128,6 +128,7 @@ public: | |||
128 | } | 128 | } |
129 | return true; | 129 | return true; |
130 | })){}; | 130 | })){}; |
131 | return Akonadi2::Storage::maxRevision(transaction); | ||
131 | } | 132 | } |
132 | 133 | ||
133 | }; | 134 | }; |
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 | ||
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index 4c58b91..f21de70 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp | |||
@@ -25,14 +25,16 @@ class TestEntityStorage : public EntityStorage<Akonadi2::ApplicationDomain::Even | |||
25 | { | 25 | { |
26 | public: | 26 | public: |
27 | using EntityStorage::EntityStorage; | 27 | using EntityStorage::EntityStorage; |
28 | virtual void read(const Akonadi2::Query &query, const QPair<qint64, qint64> &revisionRange, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) Q_DECL_OVERRIDE | 28 | virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) Q_DECL_OVERRIDE |
29 | { | 29 | { |
30 | for (const auto &res : mResults) { | 30 | for (const auto &res : mResults) { |
31 | resultProvider->add(res); | 31 | resultProvider->add(res); |
32 | } | 32 | } |
33 | return mLatestRevision; | ||
33 | } | 34 | } |
34 | 35 | ||
35 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; | 36 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; |
37 | qint64 mLatestRevision; | ||
36 | }; | 38 | }; |
37 | 39 | ||
38 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | 40 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface |
@@ -117,6 +119,7 @@ private Q_SLOTS: | |||
117 | //Enter a second result | 119 | //Enter a second result |
118 | storage->mResults.clear(); | 120 | storage->mResults.clear(); |
119 | storage->mResults << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); | 121 | storage->mResults << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); |
122 | storage->mLatestRevision = 2; | ||
120 | resourceAccess->emit revisionChanged(2); | 123 | resourceAccess->emit revisionChanged(2); |
121 | 124 | ||
122 | //Hack to get event loop in synclistresult to abort again | 125 | //Hack to get event loop in synclistresult to abort again |