summaryrefslogtreecommitdiffstats
path: root/common/datastorequery.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-26 14:19:44 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-26 14:19:44 +0200
commit47b9f2109f57c1121b760ea6d885ab08f12c46b3 (patch)
treec65e57788d5fda221a9369353bb469cbd6a066c3 /common/datastorequery.cpp
parentbe8dba1827ec54ec11d9a3ef143db9ad7f7f38df (diff)
downloadsink-47b9f2109f57c1121b760ea6d885ab08f12c46b3.tar.gz
sink-47b9f2109f57c1121b760ea6d885ab08f12c46b3.zip
Blooming
Diffstat (limited to 'common/datastorequery.cpp')
-rw-r--r--common/datastorequery.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp
index 7c0fdea..f352b74 100644
--- a/common/datastorequery.cpp
+++ b/common/datastorequery.cpp
@@ -214,6 +214,39 @@ public:
214 } 214 }
215}; 215};
216 216
217class Bloom : public FilterBase {
218public:
219 typedef QSharedPointer<Bloom> Ptr;
220
221 QByteArray mBloomProperty;
222
223 Bloom(const QByteArray &bloomProperty, FilterBase::Ptr source, DataStoreQuery *store)
224 : FilterBase(source, store),
225 mBloomProperty(bloomProperty)
226 {
227
228 }
229
230 virtual ~Bloom(){}
231
232 bool next(const std::function<void(Sink::Operation operation, const QByteArray &uid, const Sink::EntityBuffer &entityBuffer)> &callback) Q_DECL_OVERRIDE {
233 bool foundValue = false;
234 while(!foundValue && mSource->next([this, callback, &foundValue](Sink::Operation operation, const QByteArray &uid, const Sink::EntityBuffer &entityBuffer) {
235 auto bloomValue = getProperty(entityBuffer.entity(), mBloomProperty);
236 auto results = indexLookup(mBloomProperty, bloomValue);
237 for (const auto r : results) {
238 readEntity(r, [&, this](const QByteArray &uid, const Sink::EntityBuffer &entityBuffer) {
239 callback(Sink::Operation_Creation, uid, entityBuffer);
240 foundValue = true;
241 });
242 }
243 return false;
244 }))
245 {}
246 return foundValue;
247 }
248};
249
217DataStoreQuery::DataStoreQuery(const Sink::Query &query, const QByteArray &type, Sink::Storage::Transaction &transaction, TypeIndex &typeIndex, std::function<QVariant(const Sink::Entity &entity, const QByteArray &property)> getProperty) 250DataStoreQuery::DataStoreQuery(const Sink::Query &query, const QByteArray &type, Sink::Storage::Transaction &transaction, TypeIndex &typeIndex, std::function<QVariant(const Sink::Entity &entity, const QByteArray &property)> getProperty)
218 : mQuery(query), mTransaction(transaction), mType(type), mTypeIndex(typeIndex), mDb(Storage::mainDatabase(mTransaction, mType)), mGetProperty(getProperty) 251 : mQuery(query), mTransaction(transaction), mType(type), mTypeIndex(typeIndex), mDb(Storage::mainDatabase(mTransaction, mType)), mGetProperty(getProperty)
219{ 252{
@@ -383,6 +416,10 @@ void DataStoreQuery::setupQuery()
383 auto reduce = Reduce::Ptr::create("threadId", "date", Reduce::Max, baseSet, this); 416 auto reduce = Reduce::Ptr::create("threadId", "date", Reduce::Max, baseSet, this);
384 baseSet = reduce; 417 baseSet = reduce;
385 } 418 }
419 if (mQuery.bloomThread) {
420 auto reduce = Bloom::Ptr::create("threadId", baseSet, this);
421 baseSet = reduce;
422 }
386 423
387 mCollector = Collector::Ptr::create(baseSet, this); 424 mCollector = Collector::Ptr::create(baseSet, this);
388} 425}