diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-27 16:56:17 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-31 19:38:57 +0100 |
commit | 871a048580d5a464fb697713a5e0e2c52dee5208 (patch) | |
tree | 3cdc2bff1e9267b75448b9ca52b84fe46841e23e /common/datastorequery.cpp | |
parent | 8ddf4c9d2967ba4acc4121f8e845c07e421d9b23 (diff) | |
download | sink-871a048580d5a464fb697713a5e0e2c52dee5208.tar.gz sink-871a048580d5a464fb697713a5e0e2c52dee5208.zip |
Ensure blooming queries filter as they should
After the initial bloom, it should turn into a regular filter.
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r-- | common/datastorequery.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
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: | |||
101 | 101 | ||
102 | virtual ~Filter(){} | 102 | virtual ~Filter(){} |
103 | 103 | ||
104 | bool next(const std::function<void(const ResultSet::Result &result)> &callback) Q_DECL_OVERRIDE { | 104 | virtual bool next(const std::function<void(const ResultSet::Result &result)> &callback) Q_DECL_OVERRIDE { |
105 | bool foundValue = false; | 105 | bool foundValue = false; |
106 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { | 106 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { |
107 | SinkTrace() << "Filter: " << result.entity.identifier() << result.operation; | 107 | SinkTrace() << "Filter: " << result.entity.identifier() << result.operation; |
@@ -273,14 +273,14 @@ public: | |||
273 | } | 273 | } |
274 | }; | 274 | }; |
275 | 275 | ||
276 | class Bloom : public FilterBase { | 276 | class Bloom : public Filter { |
277 | public: | 277 | public: |
278 | typedef QSharedPointer<Bloom> Ptr; | 278 | typedef QSharedPointer<Bloom> Ptr; |
279 | 279 | ||
280 | QByteArray mBloomProperty; | 280 | QByteArray mBloomProperty; |
281 | 281 | ||
282 | Bloom(const QByteArray &bloomProperty, FilterBase::Ptr source, DataStoreQuery *store) | 282 | Bloom(const QByteArray &bloomProperty, FilterBase::Ptr source, DataStoreQuery *store) |
283 | : FilterBase(source, store), | 283 | : Filter(source, store), |
284 | mBloomProperty(bloomProperty) | 284 | mBloomProperty(bloomProperty) |
285 | { | 285 | { |
286 | 286 | ||
@@ -289,21 +289,33 @@ public: | |||
289 | virtual ~Bloom(){} | 289 | virtual ~Bloom(){} |
290 | 290 | ||
291 | bool next(const std::function<void(const ResultSet::Result &result)> &callback) Q_DECL_OVERRIDE { | 291 | bool next(const std::function<void(const ResultSet::Result &result)> &callback) Q_DECL_OVERRIDE { |
292 | bool foundValue = false; | 292 | if (!mBloomed) { |
293 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { | 293 | //Initially we bloom on the first value that matches. |
294 | auto bloomValue = result.entity.getProperty(mBloomProperty); | 294 | //From there on we just filter. |
295 | auto results = indexLookup(mBloomProperty, bloomValue); | 295 | bool foundValue = false; |
296 | for (const auto &r : results) { | 296 | while(!foundValue && mSource->next([this, callback, &foundValue](const ResultSet::Result &result) { |
297 | readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { | 297 | mBloomValue = result.entity.getProperty(mBloomProperty); |
298 | callback({entity, Sink::Operation_Creation}); | 298 | auto results = indexLookup(mBloomProperty, mBloomValue); |
299 | foundValue = true; | 299 | SinkWarning() << "Bloomed on value " << mBloomValue << " and found " << results.size(); |
300 | }); | 300 | for (const auto &r : results) { |
301 | } | 301 | readEntity(r, [&, this](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { |
302 | return false; | 302 | callback({entity, Sink::Operation_Creation}); |
303 | })) | 303 | foundValue = true; |
304 | {} | 304 | }); |
305 | return foundValue; | 305 | } |
306 | return false; | ||
307 | })) | ||
308 | {} | ||
309 | mBloomed = true; | ||
310 | propertyFilter.insert(mBloomProperty, mBloomValue); | ||
311 | return foundValue; | ||
312 | } else { | ||
313 | //Filter on bloom value | ||
314 | return Filter::next(callback); | ||
315 | } | ||
306 | } | 316 | } |
317 | QVariant mBloomValue; | ||
318 | bool mBloomed = false; | ||
307 | }; | 319 | }; |
308 | 320 | ||
309 | DataStoreQuery::DataStoreQuery(const Sink::QueryBase &query, const QByteArray &type, EntityStore &store) | 321 | DataStoreQuery::DataStoreQuery(const Sink::QueryBase &query, const QByteArray &type, EntityStore &store) |