summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/datastorequery.cpp35
-rw-r--r--common/mail/threadindexer.cpp5
2 files changed, 23 insertions, 17 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp
index 4c95606..ad21910 100644
--- a/common/datastorequery.cpp
+++ b/common/datastorequery.cpp
@@ -524,6 +524,7 @@ void DataStoreQuery::setupQuery(const Sink::QueryBase &query_)
524{ 524{
525 auto query = query_; 525 auto query = query_;
526 auto baseFilters = query.getBaseFilters(); 526 auto baseFilters = query.getBaseFilters();
527 //Resolve any subqueries we have
527 for (const auto &k : baseFilters.keys()) { 528 for (const auto &k : baseFilters.keys()) {
528 const auto comparator = baseFilters.value(k); 529 const auto comparator = baseFilters.value(k);
529 if (comparator.value.canConvert<Query>()) { 530 if (comparator.value.canConvert<Query>()) {
@@ -534,26 +535,26 @@ void DataStoreQuery::setupQuery(const Sink::QueryBase &query_)
534 } 535 }
535 query.setBaseFilters(baseFilters); 536 query.setBaseFilters(baseFilters);
536 537
537 FilterBase::Ptr baseSet;
538 QSet<QByteArray> remainingFilters = query.getBaseFilters().keys().toSet();
539 QByteArray appliedSorting; 538 QByteArray appliedSorting;
540 if (!query.ids().isEmpty()) { 539
541 mSource = Source::Ptr::create(query.ids().toVector(), this); 540 //Determine initial set
542 baseSet = mSource; 541 mSource = [&]() {
543 } else { 542 if (!query.ids().isEmpty()) {
544 QSet<QByteArray> appliedFilters; 543 //We have a set of ids as a starting point
545 544 return Source::Ptr::create(query.ids().toVector(), this);
546 auto resultSet = mStore.indexLookup(mType, query, appliedFilters, appliedSorting);
547 remainingFilters = remainingFilters - appliedFilters;
548
549 // We do a full scan if there were no indexes available to create the initial set.
550 if (appliedFilters.isEmpty()) {
551 mSource = Source::Ptr::create(mStore.fullScan(mType), this);
552 } else { 545 } else {
553 mSource = Source::Ptr::create(resultSet, this); 546 QSet<QByteArray> appliedFilters;
547 auto resultSet = mStore.indexLookup(mType, query, appliedFilters, appliedSorting);
548 if (!appliedFilters.isEmpty()) {
549 //We have an index lookup as starting point
550 return Source::Ptr::create(resultSet, this);
551 }
552 // We do a full scan if there were no indexes available to create the initial set (this is going to be expensive for large sets).
553 return Source::Ptr::create(mStore.fullScan(mType), this);
554 } 554 }
555 baseSet = mSource; 555 }();
556 } 556
557 FilterBase::Ptr baseSet = mSource;
557 if (!query.getBaseFilters().isEmpty()) { 558 if (!query.getBaseFilters().isEmpty()) {
558 auto filter = Filter::Ptr::create(baseSet, this); 559 auto filter = Filter::Ptr::create(baseSet, this);
559 //For incremental queries the remaining filters are not sufficient 560 //For incremental queries the remaining filters are not sufficient
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index 1401fc8..68f7af7 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -46,6 +46,11 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
46 if (!parentThread.isEmpty()) { 46 if (!parentThread.isEmpty()) {
47 auto childThreadId = thread.first(); 47 auto childThreadId = thread.first();
48 auto parentThreadId = parentThread.first(); 48 auto parentThreadId = parentThread.first();
49 //Can happen if the message is already available locally.
50 if (childThreadId == parentThreadId) {
51 //Nothing to do
52 return;
53 }
49 SinkTrace() << "Merging child thread: " << childThreadId << " into parent thread: " << parentThreadId; 54 SinkTrace() << "Merging child thread: " << childThreadId << " into parent thread: " << parentThreadId;
50 55
51 //Ensure this mail ends up in the correct thread 56 //Ensure this mail ends up in the correct thread