summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-02 14:33:21 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-02 14:34:07 +0200
commitce7c9ae13defe17f0966638d63d9f7f55806ac76 (patch)
tree5e4d28bfd7d14d42c00ed5e2d6ec3292c4b2d25d
parent0207fc55ee236d8c57a9896ebd4defc4d55369ce (diff)
downloadsink-ce7c9ae13defe17f0966638d63d9f7f55806ac76.tar.gz
sink-ce7c9ae13defe17f0966638d63d9f7f55806ac76.zip
Fixed yet another reduction update codepath
-rw-r--r--common/datastorequery.cpp14
-rw-r--r--tests/querytest.cpp47
2 files changed, 53 insertions, 8 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp
index fd910f8..4c25710 100644
--- a/common/datastorequery.cpp
+++ b/common/datastorequery.cpp
@@ -361,10 +361,6 @@ public:
361 361
362 auto oldSelectionResult = mSelectedValues.take(reductionValueBa); 362 auto oldSelectionResult = mSelectedValues.take(reductionValueBa);
363 SinkTraceCtx(mDatastore->mLogCtx) << "Old selection result: " << oldSelectionResult << " New selection result: " << selectionResult.selection; 363 SinkTraceCtx(mDatastore->mLogCtx) << "Old selection result: " << oldSelectionResult << " New selection result: " << selectionResult.selection;
364 //If mSelectedValues did not containthe value, oldSelectionResult will be empty.(Happens if entites have been filtered)
365 if (oldSelectionResult.isEmpty()) {
366 return;
367 }
368 if (oldSelectionResult == selectionResult.selection) { 364 if (oldSelectionResult == selectionResult.selection) {
369 mSelectedValues.insert(reductionValueBa, selectionResult.selection); 365 mSelectedValues.insert(reductionValueBa, selectionResult.selection);
370 Q_ASSERT(!selectionResult.selection.isEmpty()); 366 Q_ASSERT(!selectionResult.selection.isEmpty());
@@ -373,10 +369,12 @@ public:
373 }); 369 });
374 } else { 370 } else {
375 //remove old result 371 //remove old result
376 Q_ASSERT(!oldSelectionResult.isEmpty()); 372 //If mSelectedValues did not containthe value, oldSelectionResult will be empty.(Happens if entites have been filtered)
377 readEntity(oldSelectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { 373 if (!oldSelectionResult.isEmpty()) {
378 callback({entity, Sink::Operation_Removal}); 374 readEntity(oldSelectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) {
379 }); 375 callback({entity, Sink::Operation_Removal});
376 });
377 }
380 378
381 //If the last item has been removed, then there's nothing to add 379 //If the last item has been removed, then there's nothing to add
382 if (!selectionResult.selection.isEmpty()) { 380 if (!selectionResult.selection.isEmpty()) {
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index 7685086..f320d57 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -1008,6 +1008,53 @@ private slots:
1008 QTRY_COMPARE(model->rowCount(), 1); 1008 QTRY_COMPARE(model->rowCount(), 1);
1009 } 1009 }
1010 1010
1011 /*
1012 * Two messages in the same thread. The first get's filtered, the second one makes it.
1013 */
1014 void testFilteredReductionUpdateInSameThread()
1015 {
1016 // Setup
1017 auto folder1 = Folder::createEntity<Folder>("sink.dummy.instance1");
1018 VERIFYEXEC(Sink::Store::create<Folder>(folder1));
1019
1020 auto folder2 = Folder::createEntity<Folder>("sink.dummy.instance1");
1021 VERIFYEXEC(Sink::Store::create<Folder>(folder2));
1022
1023 // Ensure all local data is processed
1024 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1"));
1025
1026 Query query;
1027 query.setId("testFilteredReductionUpdate");
1028 query.setFlags(Query::LiveQuery);
1029 query.filter<Mail::Folder>(folder1);
1030 query.reduce<Mail::MessageId>(Query::Reduce::Selector::max<Mail::Date>());
1031
1032 auto model = Sink::Store::loadModel<Mail>(query);
1033 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
1034 QCOMPARE(model->rowCount(), 0);
1035
1036 //The first message will be filtered (but would be aggreagted together with the message that passes)
1037 {
1038 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1");
1039 mail.setExtractedMessageId("aggregatedId");
1040 mail.setFolder(folder2);
1041 VERIFYEXEC(Sink::Store::create(mail));
1042 }
1043
1044 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1"));
1045 QCOMPARE(model->rowCount(), 0);
1046
1047 //Ensure the non-filtered still gets through.
1048 {
1049 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1");
1050 mail.setExtractedMessageId("aggregatedId");
1051 mail.setFolder(folder1);
1052 VERIFYEXEC(Sink::Store::create(mail));
1053 }
1054 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1"));
1055 QTRY_COMPARE(model->rowCount(), 1);
1056 }
1057
1011 void testBloom() 1058 void testBloom()
1012 { 1059 {
1013 // Setup 1060 // Setup