From 871a048580d5a464fb697713a5e0e2c52dee5208 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 27 Jan 2017 16:56:17 +0100 Subject: Ensure blooming queries filter as they should After the initial bloom, it should turn into a regular filter. --- common/datastorequery.cpp | 46 +++++++++++++++++++++------------ common/domain/applicationdomaintype.cpp | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) (limited to 'common') diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index d90d546..087f405 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp @@ -101,7 +101,7 @@ public: virtual ~Filter(){} - bool next(const std::function &callback) Q_DECL_OVERRIDE { + virtual bool next(const std::function &callback) Q_DECL_OVERRIDE { bool foundValue = false; while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { SinkTrace() << "Filter: " << result.entity.identifier() << result.operation; @@ -273,14 +273,14 @@ public: } }; -class Bloom : public FilterBase { +class Bloom : public Filter { public: typedef QSharedPointer Ptr; QByteArray mBloomProperty; Bloom(const QByteArray &bloomProperty, FilterBase::Ptr source, DataStoreQuery *store) - : FilterBase(source, store), + : Filter(source, store), mBloomProperty(bloomProperty) { @@ -289,21 +289,33 @@ public: virtual ~Bloom(){} bool next(const std::function &callback) Q_DECL_OVERRIDE { - bool foundValue = false; - while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { - auto bloomValue = result.entity.getProperty(mBloomProperty); - auto results = indexLookup(mBloomProperty, bloomValue); - for (const auto &r : results) { - readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { - callback({entity, Sink::Operation_Creation}); - foundValue = true; - }); - } - return false; - })) - {} - return foundValue; + if (!mBloomed) { + //Initially we bloom on the first value that matches. + //From there on we just filter. + bool foundValue = false; + while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { + mBloomValue = result.entity.getProperty(mBloomProperty); + auto results = indexLookup(mBloomProperty, mBloomValue); + SinkWarning() << "Bloomed on value " << mBloomValue << " and found " << results.size(); + for (const auto &r : results) { + readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { + callback({entity, Sink::Operation_Creation}); + foundValue = true; + }); + } + return false; + })) + {} + mBloomed = true; + propertyFilter.insert(mBloomProperty, mBloomValue); + return foundValue; + } else { + //Filter on bloom value + return Filter::next(callback); + } } + QVariant mBloomValue; + bool mBloomed = false; }; DataStoreQuery::DataStoreQuery(const Sink::QueryBase &query, const QByteArray &type, EntityStore &store) diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 6d16a3c..57d0f2d 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -30,6 +30,7 @@ namespace Sink { namespace ApplicationDomain { constexpr const char *Mail::ThreadId::name; +constexpr const char *Mail::Folder::name; static const int foo = [] { QMetaType::registerEqualsComparator(); -- cgit v1.2.3