diff options
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r-- | common/datastorequery.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 50158c7..218796f 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -252,11 +252,18 @@ public: | |||
252 | return false; | 252 | return false; |
253 | } | 253 | } |
254 | 254 | ||
255 | QByteArray reduceOnValue(const QVariant &reductionValue, QMap<QByteArray, QVariant> &aggregateValues) | 255 | struct ReductionResult { |
256 | QByteArray selection; | ||
257 | QVector<QByteArray> aggregateIds; | ||
258 | QMap<QByteArray, QVariant> aggregateValues; | ||
259 | }; | ||
260 | |||
261 | ReductionResult reduceOnValue(const QVariant &reductionValue) | ||
256 | { | 262 | { |
263 | QMap<QByteArray, QVariant> aggregateValues; | ||
257 | QVariant selectionResultValue; | 264 | QVariant selectionResultValue; |
258 | QByteArray selectionResult; | 265 | QByteArray selectionResult; |
259 | auto results = indexLookup(mReductionProperty, reductionValue); | 266 | const auto results = indexLookup(mReductionProperty, reductionValue); |
260 | for (auto &aggregator : mAggregators) { | 267 | for (auto &aggregator : mAggregators) { |
261 | aggregator.reset(); | 268 | aggregator.reset(); |
262 | } | 269 | } |
@@ -287,7 +294,7 @@ public: | |||
287 | for (auto &aggregator : mAggregators) { | 294 | for (auto &aggregator : mAggregators) { |
288 | aggregateValues.insert(aggregator.resultProperty, aggregator.result()); | 295 | aggregateValues.insert(aggregator.resultProperty, aggregator.result()); |
289 | } | 296 | } |
290 | return selectionResult; | 297 | return {selectionResult, results, aggregateValues}; |
291 | } | 298 | } |
292 | 299 | ||
293 | 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 { |
@@ -302,12 +309,11 @@ public: | |||
302 | if (!mReducedValues.contains(reductionValueBa)) { | 309 | if (!mReducedValues.contains(reductionValueBa)) { |
303 | //Only reduce every value once. | 310 | //Only reduce every value once. |
304 | mReducedValues.insert(reductionValueBa); | 311 | mReducedValues.insert(reductionValueBa); |
305 | QMap<QByteArray, QVariant> aggregateValues; | 312 | auto reductionResult = reduceOnValue(reductionValue); |
306 | auto selectionResult = reduceOnValue(reductionValue, aggregateValues); | ||
307 | 313 | ||
308 | mSelectedValues.insert(reductionValueBa, selectionResult); | 314 | mSelectedValues.insert(reductionValueBa, reductionResult.selection); |
309 | readEntity(selectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { | 315 | readEntity(reductionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { |
310 | callback({entity, operation, aggregateValues}); | 316 | callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds}); |
311 | foundValue = true; | 317 | foundValue = true; |
312 | }); | 318 | }); |
313 | } else { | 319 | } else { |
@@ -317,15 +323,14 @@ public: | |||
317 | if (mIncremental && !mIncrementallyReducedValues.contains(reductionValueBa)) { | 323 | if (mIncremental && !mIncrementallyReducedValues.contains(reductionValueBa)) { |
318 | mIncrementallyReducedValues.insert(reductionValueBa); | 324 | mIncrementallyReducedValues.insert(reductionValueBa); |
319 | //Redo the reduction to find new aggregated values | 325 | //Redo the reduction to find new aggregated values |
320 | QMap<QByteArray, QVariant> aggregateValues; | 326 | auto selectionResult = reduceOnValue(reductionValue); |
321 | auto selectionResult = reduceOnValue(reductionValue, aggregateValues); | ||
322 | 327 | ||
323 | //TODO if old and new are the same a modification would be enough | 328 | //TODO if old and new are the same a modification would be enough |
324 | auto oldSelectionResult = mSelectedValues.take(reductionValueBa); | 329 | auto oldSelectionResult = mSelectedValues.take(reductionValueBa); |
325 | if (oldSelectionResult == selectionResult) { | 330 | if (oldSelectionResult == selectionResult.selection) { |
326 | mSelectedValues.insert(reductionValueBa, selectionResult); | 331 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); |
327 | readEntity(selectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { | 332 | readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { |
328 | callback({entity, Sink::Operation_Modification, aggregateValues}); | 333 | callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds}); |
329 | }); | 334 | }); |
330 | } else { | 335 | } else { |
331 | //remove old result | 336 | //remove old result |
@@ -334,9 +339,9 @@ public: | |||
334 | }); | 339 | }); |
335 | 340 | ||
336 | //add new result | 341 | //add new result |
337 | mSelectedValues.insert(reductionValueBa, selectionResult); | 342 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); |
338 | readEntity(selectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { | 343 | readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { |
339 | callback({entity, Sink::Operation_Creation, aggregateValues}); | 344 | callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds}); |
340 | }); | 345 | }); |
341 | } | 346 | } |
342 | } | 347 | } |
@@ -648,7 +653,7 @@ ResultSet DataStoreQuery::execute() | |||
648 | if (mCollector->next([this, callback](const ResultSet::Result &result) { | 653 | if (mCollector->next([this, callback](const ResultSet::Result &result) { |
649 | if (result.operation != Sink::Operation_Removal) { | 654 | if (result.operation != Sink::Operation_Removal) { |
650 | SinkTraceCtx(mLogCtx) << "Got initial result: " << result.entity.identifier() << result.operation; | 655 | SinkTraceCtx(mLogCtx) << "Got initial result: " << result.entity.identifier() << result.operation; |
651 | callback(ResultSet::Result{result.entity, Sink::Operation_Creation, result.aggregateValues}); | 656 | callback(ResultSet::Result{result.entity, Sink::Operation_Creation, result.aggregateValues, result.aggregateIds}); |
652 | } | 657 | } |
653 | })) | 658 | })) |
654 | { | 659 | { |