diff options
Diffstat (limited to 'common/domain')
-rw-r--r-- | common/domain/event.cpp | 1 | ||||
-rw-r--r-- | common/domain/event.h | 5 | ||||
-rw-r--r-- | common/domain/folder.cpp | 1 | ||||
-rw-r--r-- | common/domain/folder.h | 4 | ||||
-rw-r--r-- | common/domain/mail.cpp | 53 | ||||
-rw-r--r-- | common/domain/mail.h | 3 |
6 files changed, 10 insertions, 57 deletions
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 @@ | |||
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | 35 | #include "entitybuffer.h" |
36 | #include "datastorequery.h" | ||
36 | #include "entity_generated.h" | 37 | #include "entity_generated.h" |
37 | 38 | ||
38 | #include "event_generated.h" | 39 | #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 @@ | |||
21 | #include "applicationdomaintype.h" | 21 | #include "applicationdomaintype.h" |
22 | 22 | ||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "datastorequery.h" | ||
25 | 24 | ||
26 | class ResultSet; | 25 | class ResultSet; |
27 | class QByteArray; | 26 | class QByteArray; |
@@ -31,6 +30,8 @@ class ReadPropertyMapper; | |||
31 | template<typename T> | 30 | template<typename T> |
32 | class WritePropertyMapper; | 31 | class WritePropertyMapper; |
33 | 32 | ||
33 | class DataStoreQuery; | ||
34 | |||
34 | namespace Sink { | 35 | namespace Sink { |
35 | class Query; | 36 | class Query; |
36 | 37 | ||
@@ -51,7 +52,7 @@ public: | |||
51 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; | 52 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; |
52 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; | 53 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; |
53 | static QSet<QByteArray> indexedProperties(); | 54 | static QSet<QByteArray> indexedProperties(); |
54 | static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | 55 | static QSharedPointer<DataStoreQuery> prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); |
55 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 56 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); |
56 | static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 57 | static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); |
57 | static QSharedPointer<ReadPropertyMapper<Buffer> > initializeReadPropertyMapper(); | 58 | static QSharedPointer<ReadPropertyMapper<Buffer> > 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 @@ | |||
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | 35 | #include "entitybuffer.h" |
36 | #include "datastorequery.h" | ||
36 | #include "entity_generated.h" | 37 | #include "entity_generated.h" |
37 | 38 | ||
38 | #include "folder_generated.h" | 39 | #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 @@ | |||
21 | #include "applicationdomaintype.h" | 21 | #include "applicationdomaintype.h" |
22 | 22 | ||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "datastorequery.h" | ||
25 | 24 | ||
26 | class ResultSet; | 25 | class ResultSet; |
27 | class QByteArray; | 26 | class QByteArray; |
27 | class DataStoreQuery; | ||
28 | 28 | ||
29 | template<typename T> | 29 | template<typename T> |
30 | class ReadPropertyMapper; | 30 | class ReadPropertyMapper; |
@@ -45,7 +45,7 @@ class TypeImplementation<Sink::ApplicationDomain::Folder> { | |||
45 | public: | 45 | public: |
46 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; | 46 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; |
47 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; | 47 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; |
48 | static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | 48 | static QSharedPointer<DataStoreQuery> prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); |
49 | static QSet<QByteArray> indexedProperties(); | 49 | static QSet<QByteArray> indexedProperties(); |
50 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 50 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); |
51 | static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 51 | 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 @@ | |||
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | 35 | #include "entitybuffer.h" |
36 | #include "datastorequery.h" | ||
36 | #include "entity_generated.h" | 37 | #include "entity_generated.h" |
37 | 38 | ||
38 | #include "mail_generated.h" | 39 | #include "mail_generated.h" |
@@ -210,68 +211,16 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty | |||
210 | return propertyMapper; | 211 | return propertyMapper; |
211 | } | 212 | } |
212 | 213 | ||
213 | class ThreadedDataStoreQuery : public DataStoreQuery | ||
214 | { | ||
215 | public: | ||
216 | typedef QSharedPointer<ThreadedDataStoreQuery> Ptr; | ||
217 | using DataStoreQuery::DataStoreQuery; | ||
218 | |||
219 | protected: | ||
220 | ResultSet postSortFilter(ResultSet &resultSet) Q_DECL_OVERRIDE | ||
221 | { | ||
222 | auto query = mQuery; | ||
223 | if (query.threadLeaderOnly) { | ||
224 | auto rootCollection = QSharedPointer<QMap<QByteArray, QDateTime>>::create(); | ||
225 | auto filter = [this, query, rootCollection](const QByteArray &uid, const Sink::EntityBuffer &entity) -> bool { | ||
226 | //TODO lookup thread | ||
227 | //if we got thread already in the result set compare dates and if newer replace | ||
228 | //else insert | ||
229 | |||
230 | const auto messageId = getProperty(entity.entity(), ApplicationDomain::Mail::MessageId::name).toByteArray(); | ||
231 | |||
232 | Index msgIdIndex("msgId", mTransaction); | ||
233 | Index msgIdThreadIdIndex("msgIdThreadId", mTransaction); | ||
234 | auto thread = msgIdThreadIdIndex.lookup(messageId); | ||
235 | SinkTrace() << "MsgId: " << messageId << " Thread: " << thread << getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime(); | ||
236 | |||
237 | if (rootCollection->contains(thread)) { | ||
238 | auto date = rootCollection->value(thread); | ||
239 | //The mail we have in our result already is newer, so we can ignore this one | ||
240 | //This is always true during the initial query if the set has been sorted by date. | ||
241 | if (date > getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime()) { | ||
242 | return false; | ||
243 | } | ||
244 | qWarning() << "############################################################################"; | ||
245 | qWarning() << "Found a newer mail, remove the old one"; | ||
246 | qWarning() << "############################################################################"; | ||
247 | } | ||
248 | rootCollection->insert(thread, getProperty(entity.entity(), ApplicationDomain::Mail::Date::name).toDateTime()); | ||
249 | return true; | ||
250 | }; | ||
251 | return createFilteredSet(resultSet, filter); | ||
252 | } else { | ||
253 | return resultSet; | ||
254 | } | ||
255 | } | ||
256 | }; | ||
257 | 214 | ||
258 | DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) | 215 | DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) |
259 | { | 216 | { |
260 | if (query.threadLeaderOnly) { | ||
261 | auto mapper = initializeReadPropertyMapper(); | ||
262 | return ThreadedDataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { | ||
263 | 217 | ||
264 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); | ||
265 | return mapper->getProperty(property, localBuffer); | ||
266 | }); | ||
267 | 218 | ||
268 | } else { | ||
269 | auto mapper = initializeReadPropertyMapper(); | 219 | auto mapper = initializeReadPropertyMapper(); |
270 | return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { | 220 | return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { |
271 | 221 | ||
272 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); | 222 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); |
273 | return mapper->getProperty(property, localBuffer); | 223 | return mapper->getProperty(property, localBuffer); |
274 | }); | 224 | }); |
275 | } | ||
276 | } | 225 | } |
277 | 226 | ||
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 @@ | |||
25 | 25 | ||
26 | class ResultSet; | 26 | class ResultSet; |
27 | class QByteArray; | 27 | class QByteArray; |
28 | class DataStoreQuery; | ||
28 | 29 | ||
29 | template<typename T> | 30 | template<typename T> |
30 | class ReadPropertyMapper; | 31 | class ReadPropertyMapper; |
@@ -45,7 +46,7 @@ class TypeImplementation<Sink::ApplicationDomain::Mail> { | |||
45 | public: | 46 | public: |
46 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; | 47 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; |
47 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; | 48 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; |
48 | static DataStoreQuery::Ptr prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | 49 | static QSharedPointer<DataStoreQuery> prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); |
49 | static QSet<QByteArray> indexedProperties(); | 50 | static QSet<QByteArray> indexedProperties(); |
50 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 51 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); |
51 | static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 52 | static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); |