diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 10:16:18 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 10:16:18 +0100 |
commit | 2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b (patch) | |
tree | 50115abf9b041d66ab9e4242af52cd16a7a9a3db /common | |
parent | 280b1250c0a038c2cf09fae3848ed0adefecc430 (diff) | |
download | sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.tar.gz sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.zip |
Deal with removals in reduced queries
Diffstat (limited to 'common')
-rw-r--r-- | common/datastorequery.cpp | 22 | ||||
-rw-r--r-- | common/datastorequery.h | 7 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 2 |
3 files changed, 25 insertions, 6 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 218796f..dacc8ab 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -300,11 +300,18 @@ public: | |||
300 | bool next(const std::function<void(const ResultSet::Result &)> &callback) Q_DECL_OVERRIDE { | 300 | bool next(const std::function<void(const ResultSet::Result &)> &callback) Q_DECL_OVERRIDE { |
301 | bool foundValue = false; | 301 | bool foundValue = false; |
302 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { | 302 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { |
303 | if (result.operation == Sink::Operation_Removal) { | 303 | const auto reductionValue = [&] { |
304 | callback(result); | 304 | if (result.operation == Sink::Operation_Removal) { |
305 | return false; | 305 | //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. |
306 | } | 306 | QVariant reductionValue; |
307 | auto reductionValue = result.entity.getProperty(mReductionProperty); | 307 | readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { |
308 | reductionValue = prev.getProperty(mReductionProperty); | ||
309 | }); | ||
310 | return reductionValue; | ||
311 | } else { | ||
312 | return result.entity.getProperty(mReductionProperty); | ||
313 | } | ||
314 | }(); | ||
308 | const auto &reductionValueBa = getByteArray(reductionValue); | 315 | const auto &reductionValueBa = getByteArray(reductionValue); |
309 | if (!mReducedValues.contains(reductionValueBa)) { | 316 | if (!mReducedValues.contains(reductionValueBa)) { |
310 | //Only reduce every value once. | 317 | //Only reduce every value once. |
@@ -439,6 +446,11 @@ void DataStoreQuery::readEntity(const QByteArray &key, const BufferCallback &res | |||
439 | mStore.readLatest(mType, key, resultCallback); | 446 | mStore.readLatest(mType, key, resultCallback); |
440 | } | 447 | } |
441 | 448 | ||
449 | void DataStoreQuery::readPrevious(const QByteArray &key, const std::function<void (const ApplicationDomain::ApplicationDomainType &)> &callback) | ||
450 | { | ||
451 | mStore.readPrevious(mType, key, mStore.maxRevision(), callback); | ||
452 | } | ||
453 | |||
442 | QVector<QByteArray> DataStoreQuery::indexLookup(const QByteArray &property, const QVariant &value) | 454 | QVector<QByteArray> DataStoreQuery::indexLookup(const QByteArray &property, const QVariant &value) |
443 | { | 455 | { |
444 | return mStore.indexLookup(mType, property, value); | 456 | return mStore.indexLookup(mType, property, value); |
diff --git a/common/datastorequery.h b/common/datastorequery.h index 8800644..2311585 100644 --- a/common/datastorequery.h +++ b/common/datastorequery.h | |||
@@ -62,6 +62,7 @@ private: | |||
62 | QVector<QByteArray> indexLookup(const QByteArray &property, const QVariant &value); | 62 | QVector<QByteArray> indexLookup(const QByteArray &property, const QVariant &value); |
63 | 63 | ||
64 | void readEntity(const QByteArray &key, const BufferCallback &resultCallback); | 64 | void readEntity(const QByteArray &key, const BufferCallback &resultCallback); |
65 | void readPrevious(const QByteArray &key, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback); | ||
65 | 66 | ||
66 | ResultSet createFilteredSet(ResultSet &resultSet, const FilterFunction &); | 67 | ResultSet createFilteredSet(ResultSet &resultSet, const FilterFunction &); |
67 | QVector<QByteArray> loadIncrementalResultSet(qint64 baseRevision); | 68 | QVector<QByteArray> loadIncrementalResultSet(qint64 baseRevision); |
@@ -107,6 +108,12 @@ public: | |||
107 | return mDatastore->indexLookup(property, value); | 108 | return mDatastore->indexLookup(property, value); |
108 | } | 109 | } |
109 | 110 | ||
111 | void readPrevious(const QByteArray &key, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback) | ||
112 | { | ||
113 | Q_ASSERT(mDatastore); | ||
114 | mDatastore->readPrevious(key, callback); | ||
115 | } | ||
116 | |||
110 | virtual void skip() { mSource->skip(); } | 117 | virtual void skip() { mSource->skip(); } |
111 | 118 | ||
112 | //Returns true for as long as a result is available | 119 | //Returns true for as long as a result is available |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 020f3fd..7da7efa 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -563,7 +563,7 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi | |||
563 | return true; | 563 | return true; |
564 | }, | 564 | }, |
565 | [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); | 565 | [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); |
566 | return readEntity(type, Sink::Storage::DataStore::assembleKey(uid, latestRevision), callback); | 566 | readEntity(type, Sink::Storage::DataStore::assembleKey(uid, latestRevision), callback); |
567 | } | 567 | } |
568 | 568 | ||
569 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) | 569 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) |