diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-23 01:35:13 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-23 01:35:13 +0200 |
commit | 52ad48c8bd755a2fde249296d6017853538f478f (patch) | |
tree | d3adbee13e49d2525720069cb7d9ca6b5876dbd8 /common/domain/mail.cpp | |
parent | 6fc76bc690e5a2e7748936fa835338d820c7e7de (diff) | |
download | sink-52ad48c8bd755a2fde249296d6017853538f478f.tar.gz sink-52ad48c8bd755a2fde249296d6017853538f478f.zip |
A new query system
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r-- | common/domain/mail.cpp | 53 |
1 files changed, 1 insertions, 52 deletions
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 | ||