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/datastorequery.cpp | |
parent | 280b1250c0a038c2cf09fae3848ed0adefecc430 (diff) | |
download | sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.tar.gz sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.zip |
Deal with removals in reduced queries
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r-- | common/datastorequery.cpp | 22 |
1 files changed, 17 insertions, 5 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); |