From 52ad48c8bd755a2fde249296d6017853538f478f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 23 Sep 2016 01:35:13 +0200 Subject: A new query system --- common/domain/event.cpp | 1 + common/domain/event.h | 5 +++-- common/domain/folder.cpp | 1 + common/domain/folder.h | 4 ++-- common/domain/mail.cpp | 53 +----------------------------------------------- common/domain/mail.h | 3 ++- 6 files changed, 10 insertions(+), 57 deletions(-) (limited to 'common/domain') diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 118ffa3..f3abd62 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -33,6 +33,7 @@ #include "../definitions.h" #include "../typeindex.h" #include "entitybuffer.h" +#include "datastorequery.h" #include "entity_generated.h" #include "event_generated.h" diff --git a/common/domain/event.h b/common/domain/event.h index e1ca061..684b58e 100644 --- a/common/domain/event.h +++ b/common/domain/event.h @@ -21,7 +21,6 @@ #include "applicationdomaintype.h" #include "storage.h" -#include "datastorequery.h" class ResultSet; class QByteArray; @@ -31,6 +30,8 @@ class ReadPropertyMapper; template class WritePropertyMapper; +class DataStoreQuery; + namespace Sink { class Query; @@ -51,7 +52,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Event Buffer; typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; static QSet indexedProperties(); - static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); + static QSharedPointer prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 17d9f13..824fa0b 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -33,6 +33,7 @@ #include "../definitions.h" #include "../typeindex.h" #include "entitybuffer.h" +#include "datastorequery.h" #include "entity_generated.h" #include "folder_generated.h" diff --git a/common/domain/folder.h b/common/domain/folder.h index ff87006..e4631de 100644 --- a/common/domain/folder.h +++ b/common/domain/folder.h @@ -21,10 +21,10 @@ #include "applicationdomaintype.h" #include "storage.h" -#include "datastorequery.h" class ResultSet; class QByteArray; +class DataStoreQuery; template class ReadPropertyMapper; @@ -45,7 +45,7 @@ class TypeImplementation { public: typedef Sink::ApplicationDomain::Buffer::Folder Buffer; typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; - static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); + static QSharedPointer prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); static QSet indexedProperties(); static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 0c737fa..483a2f2 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -33,6 +33,7 @@ #include "../definitions.h" #include "../typeindex.h" #include "entitybuffer.h" +#include "datastorequery.h" #include "entity_generated.h" #include "mail_generated.h" @@ -210,68 +211,16 @@ QSharedPointer::BufferBuilder> > Ty return propertyMapper; } -class ThreadedDataStoreQuery : public DataStoreQuery -{ -public: - typedef QSharedPointer Ptr; - using DataStoreQuery::DataStoreQuery; - -protected: - ResultSet postSortFilter(ResultSet &resultSet) Q_DECL_OVERRIDE - { - auto query = mQuery; - if (query.threadLeaderOnly) { - auto rootCollection = QSharedPointer>::create(); - auto filter = [this, query, rootCollection](const QByteArray &uid, const Sink::EntityBuffer &entity) -> bool { - //TODO lookup thread - //if we got thread already in the result set compare dates and if newer replace - //else insert - - const auto messageId = getProperty(entity.entity(), ApplicationDomain::Mail::MessageId::name).toByteArray(); - - Index msgIdIndex("msgId", mTransaction); - Index msgIdThreadIdIndex("msgIdThreadId", mTransaction); - auto thread = msgIdThreadIdIndex.lookup(messageId); - SinkTrace() << "MsgId: " << messageId << " Thread: " << thread << getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime(); - - if (rootCollection->contains(thread)) { - auto date = rootCollection->value(thread); - //The mail we have in our result already is newer, so we can ignore this one - //This is always true during the initial query if the set has been sorted by date. - if (date > getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime()) { - return false; - } - qWarning() << "############################################################################"; - qWarning() << "Found a newer mail, remove the old one"; - qWarning() << "############################################################################"; - } - rootCollection->insert(thread, getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime()); - return true; - }; - return createFilteredSet(resultSet, filter); - } else { - return resultSet; - } - } -}; DataStoreQuery::Ptr TypeImplementation::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) { - if (query.threadLeaderOnly) { - auto mapper = initializeReadPropertyMapper(); - return ThreadedDataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { - const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); - return mapper->getProperty(property, localBuffer); - }); - } else { auto mapper = initializeReadPropertyMapper(); return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); return mapper->getProperty(property, localBuffer); }); - } } diff --git a/common/domain/mail.h b/common/domain/mail.h index 3b0e9da..ea3ef9e 100644 --- a/common/domain/mail.h +++ b/common/domain/mail.h @@ -25,6 +25,7 @@ class ResultSet; class QByteArray; +class DataStoreQuery; template class ReadPropertyMapper; @@ -45,7 +46,7 @@ class TypeImplementation { public: typedef Sink::ApplicationDomain::Buffer::Mail Buffer; typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; - static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); + static QSharedPointer prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); static QSet indexedProperties(); static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); -- cgit v1.2.3