From 2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 22 Feb 2018 10:16:18 +0100 Subject: Deal with removals in reduced queries --- common/datastorequery.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'common/datastorequery.cpp') 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: bool next(const std::function &callback) Q_DECL_OVERRIDE { bool foundValue = false; while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { - if (result.operation == Sink::Operation_Removal) { - callback(result); - return false; - } - auto reductionValue = result.entity.getProperty(mReductionProperty); + const auto reductionValue = [&] { + if (result.operation == Sink::Operation_Removal) { + //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. + QVariant reductionValue; + readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { + reductionValue = prev.getProperty(mReductionProperty); + }); + return reductionValue; + } else { + return result.entity.getProperty(mReductionProperty); + } + }(); const auto &reductionValueBa = getByteArray(reductionValue); if (!mReducedValues.contains(reductionValueBa)) { //Only reduce every value once. @@ -439,6 +446,11 @@ void DataStoreQuery::readEntity(const QByteArray &key, const BufferCallback &res mStore.readLatest(mType, key, resultCallback); } +void DataStoreQuery::readPrevious(const QByteArray &key, const std::function &callback) +{ + mStore.readPrevious(mType, key, mStore.maxRevision(), callback); +} + QVector DataStoreQuery::indexLookup(const QByteArray &property, const QVariant &value) { return mStore.indexLookup(mType, property, value); -- cgit v1.2.3