summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-07-27 13:40:03 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-27 13:48:03 +0200
commitc741d7fbb21ff959ca4b6d4f7681aead277044b4 (patch)
tree5ba510e9d794aea0d689bde08f44fece7fc129e4
parent0a9b39a1f58c1f5b1a424acbe369db520a12df42 (diff)
downloadsink-c741d7fbb21ff959ca4b6d4f7681aead277044b4.tar.gz
sink-c741d7fbb21ff959ca4b6d4f7681aead277044b4.zip
Use Key API in ResultSet
Summary: Depends on D14099 Notes: - Tests pass without many modifications outside of resultset.cpp/.h - `mGenerator` doesn't seem to be used? Benchmarks ========= Run benchmarks: | Develop | D14099 | This patch | | ---------------------------------- | ---------------------------------- | ---------------------------------- | | Current Rss usage [kb]: 40700 | Current Rss usage [kb]: 38564 | Current Rss usage [kb]: 39112 | | Peak Rss usage [kb]: 40700 | Peak Rss usage [kb]: 38564 | Peak Rss usage [kb]: 39112 | | Rss growth [kb]: 15920 | Rss growth [kb]: 13352 | Rss growth [kb]: 13432 | | Rss growth per entity [byte]: 3260 | Rss growth per entity [byte]: 2734 | Rss growth per entity [byte]: 2750 | | Rss without db [kb]: 29736 | Rss without db [kb]: 29248 | Rss without db [kb]: 30100 | | Percentage peak rss error: 0 | Percentage peak rss error: 0 | Percentage peak rss error: 0 | | On disk [kb]: 10788 | On disk [kb]: 9140 | On disk [kb]: 8836 | | Buffer size total [kb]: 898 | Buffer size total [kb]: 898 | Buffer size total [kb]: 898 | | Write amplification: 12.0075 | Write amplification: 10.1732 | Write amplification: 9.83485 | Test Disk Usage: | Develop | D14099 | This patch | | ----------------------------------- | ----------------------------------- | ----------------------------------- | | Free pages: 412 | Free pages: 309 | Free pages: 312 | | Total pages: 760 | Total pages: 599 | Total pages: 603 | | Used size: 1425408 | Used size: 1187840 | Used size: 1191936 | | Calculated key + value size: 856932 | Calculated key + value size: 702866 | Calculated key + value size: 702866 | | Calculated total db sizes: 970752 | Calculated total db sizes: 954368 | Calculated total db sizes: 933888 | | Main store on disk: 3112960 | Main store on disk: 2453504 | Main store on disk: 2469888 | | Total on disk: 3293184 | Total on disk: 2633728 | Total on disk: 2650112 | | Used size amplification: 1.66339 | Used size amplification: 1.68999 | Used size amplification: 1.69582 | | Write amplification: 3.63268 | Write amplification: 3.49071 | Write amplification: 3.51402 | Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D14289
-rw-r--r--common/datastorequery.cpp6
-rw-r--r--common/queryrunner.cpp9
-rw-r--r--common/resultset.cpp8
-rw-r--r--common/resultset.h21
4 files changed, 29 insertions, 15 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp
index aa315c6..52243da 100644
--- a/common/datastorequery.cpp
+++ b/common/datastorequery.cpp
@@ -271,7 +271,7 @@ public:
271 271
272 struct ReductionResult { 272 struct ReductionResult {
273 Identifier selection; 273 Identifier selection;
274 QVector<QByteArray> aggregateIds; 274 QVector<Identifier> aggregateIds;
275 QMap<QByteArray, QVariant> aggregateValues; 275 QMap<QByteArray, QVariant> aggregateValues;
276 }; 276 };
277 277
@@ -284,14 +284,14 @@ public:
284 for (auto &aggregator : mAggregators) { 284 for (auto &aggregator : mAggregators) {
285 aggregator.reset(); 285 aggregator.reset();
286 } 286 }
287 QVector<QByteArray> reducedAndFilteredResults; 287 QVector<Identifier> reducedAndFilteredResults;
288 for (const auto &r : results) { 288 for (const auto &r : results) {
289 readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { 289 readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) {
290 //We need to apply all property filters that we have until the reduction, because the index lookup was unfiltered. 290 //We need to apply all property filters that we have until the reduction, because the index lookup was unfiltered.
291 if (!matchesFilter(entity)) { 291 if (!matchesFilter(entity)) {
292 return; 292 return;
293 } 293 }
294 reducedAndFilteredResults << r.toDisplayByteArray(); 294 reducedAndFilteredResults << r;
295 Q_ASSERT(operation != Sink::Operation_Removal); 295 Q_ASSERT(operation != Sink::Operation_Removal);
296 for (auto &aggregator : mAggregators) { 296 for (auto &aggregator : mAggregators) {
297 if (!aggregator.property.isEmpty()) { 297 if (!aggregator.property.isEmpty()) {
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp
index 9ac3517..7d6d279 100644
--- a/common/queryrunner.cpp
+++ b/common/queryrunner.cpp
@@ -271,7 +271,14 @@ void QueryWorker<DomainType>::resultProviderCallback(const Sink::Query &query, S
271 for (auto it = result.aggregateValues.constBegin(); it != result.aggregateValues.constEnd(); it++) { 271 for (auto it = result.aggregateValues.constBegin(); it != result.aggregateValues.constEnd(); it++) {
272 valueCopy->setProperty(it.key(), it.value()); 272 valueCopy->setProperty(it.key(), it.value());
273 } 273 }
274 valueCopy->aggregatedIds() = result.aggregateIds; 274 valueCopy->aggregatedIds() = [&] {
275 QVector<QByteArray> aggregateIdsBA;
276 aggregateIdsBA.reserve(result.aggregateIds.size());
277 for (const auto &id : result.aggregateIds) {
278 aggregateIdsBA << id.toDisplayByteArray();
279 }
280 return aggregateIdsBA;
281 }();
275 if (mResultTransformation) { 282 if (mResultTransformation) {
276 mResultTransformation(*valueCopy); 283 mResultTransformation(*valueCopy);
277 } 284 }
diff --git a/common/resultset.cpp b/common/resultset.cpp
index 08954c9..88110e1 100644
--- a/common/resultset.cpp
+++ b/common/resultset.cpp
@@ -20,6 +20,8 @@
20 20
21#include "log.h" 21#include "log.h"
22 22
23using Sink::Storage::Identifier;
24
23ResultSet::ResultSet() : mIt(nullptr) 25ResultSet::ResultSet() : mIt(nullptr)
24{ 26{
25} 27}
@@ -32,7 +34,7 @@ ResultSet::ResultSet(const IdGenerator &generator) : mIt(nullptr), mGenerator(ge
32{ 34{
33} 35}
34 36
35ResultSet::ResultSet(const QVector<QByteArray> &resultSet) 37ResultSet::ResultSet(const QVector<Identifier> &resultSet)
36 : mResultSet(resultSet), 38 : mResultSet(resultSet),
37 mIt(mResultSet.constBegin()), 39 mIt(mResultSet.constBegin()),
38 mSkip([this]() { 40 mSkip([this]() {
@@ -114,11 +116,11 @@ ResultSet::ReplayResult ResultSet::replaySet(int offset, int batchSize, const Ca
114 return {counter, false}; 116 return {counter, false};
115} 117}
116 118
117QByteArray ResultSet::id() 119Identifier ResultSet::id()
118{ 120{
119 if (mIt) { 121 if (mIt) {
120 if (mIt == mResultSet.constEnd()) { 122 if (mIt == mResultSet.constEnd()) {
121 return QByteArray(); 123 return {};
122 } 124 }
123 Q_ASSERT(mIt != mResultSet.constEnd()); 125 Q_ASSERT(mIt != mResultSet.constEnd());
124 return *mIt; 126 return *mIt;
diff --git a/common/resultset.h b/common/resultset.h
index 5587c54..9d83c67 100644
--- a/common/resultset.h
+++ b/common/resultset.h
@@ -25,6 +25,7 @@
25#include "metadata_generated.h" 25#include "metadata_generated.h"
26#include "entitybuffer.h" 26#include "entitybuffer.h"
27#include "applicationdomaintype.h" 27#include "applicationdomaintype.h"
28#include "storage/key.h"
28 29
29/* 30/*
30 * An iterator to a result set. 31 * An iterator to a result set.
@@ -35,21 +36,25 @@ class ResultSet
35{ 36{
36public: 37public:
37 struct Result { 38 struct Result {
38 Result(const Sink::ApplicationDomain::ApplicationDomainType &e, Sink::Operation op, const QMap<QByteArray, QVariant> &v = {}, const QVector<QByteArray> &a = {}) : entity(e), operation(op), aggregateValues(v), aggregateIds(a) {} 39 Result(const Sink::ApplicationDomain::ApplicationDomainType &e, Sink::Operation op,
40 const QMap<QByteArray, QVariant> &v = {}, const QVector<Sink::Storage::Identifier> &a = {})
41 : entity(e), operation(op), aggregateValues(v), aggregateIds(a)
42 {
43 }
39 Sink::ApplicationDomain::ApplicationDomainType entity; 44 Sink::ApplicationDomain::ApplicationDomainType entity;
40 Sink::Operation operation; 45 Sink::Operation operation;
41 QMap<QByteArray, QVariant> aggregateValues; 46 QMap<QByteArray, QVariant> aggregateValues;
42 QVector<QByteArray> aggregateIds; 47 QVector<Sink::Storage::Identifier> aggregateIds;
43 }; 48 };
44 typedef std::function<void(const Result &)> Callback; 49 typedef std::function<void(const Result &)> Callback;
45 typedef std::function<bool(Callback)> ValueGenerator; 50 typedef std::function<bool(Callback)> ValueGenerator;
46 typedef std::function<QByteArray()> IdGenerator; 51 typedef std::function<Sink::Storage::Identifier()> IdGenerator;
47 typedef std::function<void()> SkipValue; 52 typedef std::function<void()> SkipValue;
48 53
49 ResultSet(); 54 ResultSet();
50 ResultSet(const ValueGenerator &generator, const SkipValue &skip); 55 ResultSet(const ValueGenerator &generator, const SkipValue &skip);
51 ResultSet(const IdGenerator &generator); 56 ResultSet(const IdGenerator &generator);
52 ResultSet(const QVector<QByteArray> &resultSet); 57 ResultSet(const QVector<Sink::Storage::Identifier> &resultSet);
53 ResultSet(const ResultSet &other); 58 ResultSet(const ResultSet &other);
54 59
55 bool next(); 60 bool next();
@@ -63,14 +68,14 @@ public:
63 }; 68 };
64 ReplayResult replaySet(int offset, int batchSize, const Callback &callback); 69 ReplayResult replaySet(int offset, int batchSize, const Callback &callback);
65 70
66 QByteArray id(); 71 Sink::Storage::Identifier id();
67 72
68 bool isEmpty(); 73 bool isEmpty();
69 74
70private: 75private:
71 QVector<QByteArray> mResultSet; 76 QVector<Sink::Storage::Identifier> mResultSet;
72 QVector<QByteArray>::ConstIterator mIt; 77 QVector<Sink::Storage::Identifier>::ConstIterator mIt;
73 QByteArray mCurrentValue; 78 Sink::Storage::Identifier mCurrentValue;
74 IdGenerator mGenerator; 79 IdGenerator mGenerator;
75 ValueGenerator mValueGenerator; 80 ValueGenerator mValueGenerator;
76 SkipValue mSkip; 81 SkipValue mSkip;