summaryrefslogtreecommitdiffstats
path: root/common/datastorequery.cpp
diff options
context:
space:
mode:
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}