summaryrefslogtreecommitdiffstats
path: root/common/datastorequery.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-08 22:10:04 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-08 22:10:04 +0200
commit393846f660802d53d6ff6744cea0c1fa05019ba3 (patch)
tree2c8906240167af00838314d0b35907c87e4d40d5 /common/datastorequery.cpp
parent624fb3718b5063f29644b69a8082ef9f84a55ec5 (diff)
downloadsink-393846f660802d53d6ff6744cea0c1fa05019ba3.tar.gz
sink-393846f660802d53d6ff6744cea0c1fa05019ba3.zip
Optimized the incremental update case.
This brings the incremental closer to a regular query (about 1.5 times as bad instead of 3.5 times). For a comparison look at MailQueryBenchmark::testIncremental() The optimization is built on the assumption that we i.e. get an update with 100 revisions, and thus the optimization applies to the case where we have multiple revisions within that batch that are part of the same reduction. In such a case we can avoid redoing the reduction lookup over and over.
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r--common/datastorequery.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp
index f3d9415..f5152b7 100644
--- a/common/datastorequery.cpp
+++ b/common/datastorequery.cpp
@@ -208,6 +208,7 @@ public:
208 }; 208 };
209 209
210 QSet<QByteArray> mReducedValues; 210 QSet<QByteArray> mReducedValues;
211 QSet<QByteArray> mIncrementallyReducedValues;
211 QHash<QByteArray, QByteArray> mSelectedValues; 212 QHash<QByteArray, QByteArray> mSelectedValues;
212 QByteArray mReductionProperty; 213 QByteArray mReductionProperty;
213 QByteArray mSelectionProperty; 214 QByteArray mSelectionProperty;
@@ -225,6 +226,11 @@ public:
225 226
226 virtual ~Reduce(){} 227 virtual ~Reduce(){}
227 228
229 void updateComplete() Q_DECL_OVERRIDE
230 {
231 mIncrementallyReducedValues.clear();
232 }
233
228 static QByteArray getByteArray(const QVariant &value) { 234 static QByteArray getByteArray(const QVariant &value) {
229 if (value.type() == QVariant::DateTime) { 235 if (value.type() == QVariant::DateTime) {
230 return value.toDateTime().toString().toLatin1(); 236 return value.toDateTime().toString().toLatin1();
@@ -304,7 +310,8 @@ public:
304 //During initial query, do nothing. The lookup above will take care of it. 310 //During initial query, do nothing. The lookup above will take care of it.
305 //During updates adjust the reduction according to the modification/addition or removal 311 //During updates adjust the reduction according to the modification/addition or removal
306 //We have to redo the reduction for every element, because of the aggregation values. 312 //We have to redo the reduction for every element, because of the aggregation values.
307 if (mIncremental) { 313 if (mIncremental && !mIncrementallyReducedValues.contains(reductionValueBa)) {
314 mIncrementallyReducedValues.insert(reductionValueBa);
308 //Redo the reduction to find new aggregated values 315 //Redo the reduction to find new aggregated values
309 QMap<QByteArray, QVariant> aggregateValues; 316 QMap<QByteArray, QVariant> aggregateValues;
310 auto selectionResult = reduceOnValue(reductionValue, aggregateValues); 317 auto selectionResult = reduceOnValue(reductionValue, aggregateValues);
@@ -621,6 +628,11 @@ ResultSet DataStoreQuery::update(qint64 baseRevision)
621void DataStoreQuery::updateComplete() 628void DataStoreQuery::updateComplete()
622{ 629{
623 mSource->mIncrementalIds.clear(); 630 mSource->mIncrementalIds.clear();
631 auto source = mCollector;
632 while (source) {
633 source->updateComplete();
634 source = source->mSource;
635 }
624} 636}
625 637
626ResultSet DataStoreQuery::execute() 638ResultSet DataStoreQuery::execute()