diff options
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r-- | common/domain/mail.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 0170357..1a877cb 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp | |||
@@ -29,41 +29,40 @@ | |||
29 | #include "../propertymapper.h" | 29 | #include "../propertymapper.h" |
30 | #include "../query.h" | 30 | #include "../query.h" |
31 | #include "../definitions.h" | 31 | #include "../definitions.h" |
32 | #include "../typeindex.h" | ||
32 | 33 | ||
33 | #include "mail_generated.h" | 34 | #include "mail_generated.h" |
34 | 35 | ||
35 | using namespace Akonadi2::ApplicationDomain; | 36 | using namespace Akonadi2::ApplicationDomain; |
36 | 37 | ||
37 | ResultSet TypeImplementation<Mail>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) | 38 | static TypeIndex &getIndex() |
38 | { | 39 | { |
39 | QVector<QByteArray> keys; | 40 | static TypeIndex *index = 0; |
40 | if (query.propertyFilter.contains("uid")) { | 41 | if (!index) { |
41 | Index uidIndex("mail.index.uid", transaction); | 42 | index = new TypeIndex("mail"); |
42 | uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { | 43 | index->addProperty<QByteArray>("uid"); |
43 | keys << value; | 44 | index->addProperty<QByteArray>("sender"); |
44 | }, | 45 | index->addProperty<QByteArray>("senderName"); |
45 | [](const Index::Error &error) { | 46 | index->addProperty<QString>("subject"); |
46 | Warning() << "Error in uid index: " << error.message; | 47 | index->addProperty<QDateTime>("date"); |
47 | }); | ||
48 | appliedFilters << "uid"; | ||
49 | } | 48 | } |
50 | return ResultSet(keys); | 49 | return *index; |
50 | } | ||
51 | |||
52 | ResultSet TypeImplementation<Mail>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) | ||
53 | { | ||
54 | return getIndex().query(query, appliedFilters, transaction); | ||
51 | } | 55 | } |
52 | 56 | ||
53 | void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 57 | void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
54 | { | 58 | { |
55 | const auto uid = bufferAdaptor.getProperty("uid"); | 59 | Trace() << "Indexing " << identifier; |
56 | if (uid.isValid()) { | 60 | getIndex().add(identifier, bufferAdaptor, transaction); |
57 | Index("mail.index.uid", transaction).add(uid.toByteArray(), identifier); | ||
58 | } | ||
59 | } | 61 | } |
60 | 62 | ||
61 | void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 63 | void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
62 | { | 64 | { |
63 | const auto uid = bufferAdaptor.getProperty("uid"); | 65 | getIndex().remove(identifier, bufferAdaptor, transaction); |
64 | if (uid.isValid()) { | ||
65 | Index("mail.index.uid", transaction).remove(uid.toByteArray(), identifier); | ||
66 | } | ||
67 | } | 66 | } |
68 | 67 | ||
69 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() | 68 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() |