diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-19 12:28:17 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-19 12:28:17 +0100 |
commit | a16ae6c64b75706f9663fb27510a73d1a6a29de8 (patch) | |
tree | 2462aef115c34b652dbd7d76d66b0369fcae3763 | |
parent | 6fe54c0932d685b63c1f9cc76611ae2aa2fb42ae (diff) | |
download | sink-a16ae6c64b75706f9663fb27510a73d1a6a29de8.tar.gz sink-a16ae6c64b75706f9663fb27510a73d1a6a29de8.zip |
Handle filtered thread-leader
-rw-r--r-- | common/datastorequery.cpp | 10 | ||||
-rw-r--r-- | tests/querytest.cpp | 65 |
2 files changed, 73 insertions, 2 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 34d2bae..0db59e1 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -152,7 +152,7 @@ public: | |||
152 | } | 152 | } |
153 | }; | 153 | }; |
154 | 154 | ||
155 | class Reduce : public FilterBase { | 155 | class Reduce : public Filter { |
156 | public: | 156 | public: |
157 | typedef QSharedPointer<Reduce> Ptr; | 157 | typedef QSharedPointer<Reduce> Ptr; |
158 | 158 | ||
@@ -198,7 +198,7 @@ public: | |||
198 | QList<Aggregator> mAggregators; | 198 | QList<Aggregator> mAggregators; |
199 | 199 | ||
200 | Reduce(const QByteArray &reductionProperty, const QByteArray &selectionProperty, QueryBase::Reduce::Selector::Comparator comparator, FilterBase::Ptr source, DataStoreQuery *store) | 200 | Reduce(const QByteArray &reductionProperty, const QByteArray &selectionProperty, QueryBase::Reduce::Selector::Comparator comparator, FilterBase::Ptr source, DataStoreQuery *store) |
201 | : FilterBase(source, store), | 201 | : Filter(source, store), |
202 | mReductionProperty(reductionProperty), | 202 | mReductionProperty(reductionProperty), |
203 | mSelectionProperty(selectionProperty), | 203 | mSelectionProperty(selectionProperty), |
204 | mSelectionComparator(comparator) | 204 | mSelectionComparator(comparator) |
@@ -236,6 +236,11 @@ public: | |||
236 | 236 | ||
237 | for (const auto &r : results) { | 237 | for (const auto &r : results) { |
238 | readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { | 238 | readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { |
239 | //We need to apply all property filters that we have until the reduction, because the index lookup was unfiltered. | ||
240 | if (!matchesFilter(entity)) { | ||
241 | return; | ||
242 | } | ||
243 | |||
239 | Q_ASSERT(operation != Sink::Operation_Removal); | 244 | Q_ASSERT(operation != Sink::Operation_Removal); |
240 | for (auto &aggregator : mAggregators) { | 245 | for (auto &aggregator : mAggregators) { |
241 | if (!aggregator.property.isEmpty()) { | 246 | if (!aggregator.property.isEmpty()) { |
@@ -553,6 +558,7 @@ void DataStoreQuery::setupQuery(const Sink::QueryBase &query_) | |||
553 | for (const auto &aggregator : filter->aggregators) { | 558 | for (const auto &aggregator : filter->aggregators) { |
554 | reduction->mAggregators << Reduce::Aggregator(aggregator.operation, aggregator.propertyToCollect, aggregator.resultProperty); | 559 | reduction->mAggregators << Reduce::Aggregator(aggregator.operation, aggregator.propertyToCollect, aggregator.resultProperty); |
555 | } | 560 | } |
561 | reduction->propertyFilter = query.getBaseFilters(); | ||
556 | baseSet = reduction; | 562 | baseSet = reduction; |
557 | } else if (auto filter = stage.dynamicCast<Query::Bloom>()) { | 563 | } else if (auto filter = stage.dynamicCast<Query::Bloom>()) { |
558 | baseSet = Bloom::Ptr::create(filter->property, baseSet, this); | 564 | baseSet = Bloom::Ptr::create(filter->property, baseSet, this); |
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index bd3b927..f639d94 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -1042,6 +1042,71 @@ private slots: | |||
1042 | QCOMPARE(layoutChangedSpy.size(), 0); | 1042 | QCOMPARE(layoutChangedSpy.size(), 0); |
1043 | QCOMPARE(resetSpy.size(), 0); | 1043 | QCOMPARE(resetSpy.size(), 0); |
1044 | } | 1044 | } |
1045 | |||
1046 | /* | ||
1047 | * Ensure that we handle the situation properly if the thread-leader doesn't match a property filter. | ||
1048 | */ | ||
1049 | void testFilteredThreadLeader() | ||
1050 | { | ||
1051 | // Setup | ||
1052 | auto folder1 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
1053 | VERIFYEXEC(Sink::Store::create<Folder>(folder1)); | ||
1054 | |||
1055 | auto folder2 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
1056 | VERIFYEXEC(Sink::Store::create<Folder>(folder2)); | ||
1057 | |||
1058 | QDateTime earlier{QDate{2017, 2, 3}, QTime{9, 0, 0}}; | ||
1059 | QDateTime now{QDate{2017, 2, 3}, QTime{10, 0, 0}}; | ||
1060 | QDateTime later{QDate{2017, 2, 3}, QTime{11, 0, 0}}; | ||
1061 | |||
1062 | { | ||
1063 | auto mail1 = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
1064 | mail1.setExtractedMessageId("mail1"); | ||
1065 | mail1.setFolder(folder1); | ||
1066 | mail1.setExtractedDate(now); | ||
1067 | mail1.setImportant(false); | ||
1068 | VERIFYEXEC(Sink::Store::create(mail1)); | ||
1069 | } | ||
1070 | { | ||
1071 | auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
1072 | mail2.setExtractedMessageId("mail2"); | ||
1073 | mail2.setFolder(folder1); | ||
1074 | mail2.setExtractedDate(earlier); | ||
1075 | mail2.setImportant(false); | ||
1076 | VERIFYEXEC(Sink::Store::create(mail2)); | ||
1077 | } | ||
1078 | { | ||
1079 | auto mail3 = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
1080 | mail3.setExtractedMessageId("mail3"); | ||
1081 | mail3.setFolder(folder1); | ||
1082 | mail3.setExtractedDate(later); | ||
1083 | mail3.setImportant(true); | ||
1084 | VERIFYEXEC(Sink::Store::create(mail3)); | ||
1085 | } | ||
1086 | |||
1087 | // Ensure all local data is processed | ||
1088 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
1089 | |||
1090 | Query query; | ||
1091 | query.setId("testLivequeryThreadleaderChange"); | ||
1092 | query.setFlags(Query::LiveQuery); | ||
1093 | query.reduce<Mail::Folder>(Query::Reduce::Selector::max<Mail::Date>()).count("count").collect<Mail::Folder>("folders"); | ||
1094 | query.sort<Mail::Date>(); | ||
1095 | query.request<Mail::MessageId>(); | ||
1096 | query.filter<Mail::Important>(false); | ||
1097 | |||
1098 | auto model = Sink::Store::loadModel<Mail>(query); | ||
1099 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
1100 | |||
1101 | QCOMPARE(model->rowCount(), 1); | ||
1102 | |||
1103 | { | ||
1104 | auto mail = model->data(model->index(0, 0, QModelIndex{}), Sink::Store::DomainObjectRole).value<Mail::Ptr>(); | ||
1105 | QCOMPARE(mail->getMessageId(), QByteArray{"mail1"}); | ||
1106 | QCOMPARE(mail->getProperty("count").toInt(), 2); | ||
1107 | QCOMPARE(mail->getProperty("folders").toList().size(), 2); | ||
1108 | } | ||
1109 | } | ||
1045 | }; | 1110 | }; |
1046 | 1111 | ||
1047 | QTEST_MAIN(QueryTest) | 1112 | QTEST_MAIN(QueryTest) |