diff options
Diffstat (limited to 'common/domain/event.cpp')
-rw-r--r-- | common/domain/event.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 3036d8e..d989efe 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -29,42 +29,35 @@ | |||
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 "event_generated.h" | 34 | #include "event_generated.h" |
34 | 35 | ||
35 | using namespace Akonadi2::ApplicationDomain; | 36 | using namespace Akonadi2::ApplicationDomain; |
36 | 37 | ||
37 | ResultSet TypeImplementation<Event>::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("event.index.uid", transaction); | 42 | index = new TypeIndex("event"); |
42 | uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { | 43 | index->addProperty<QByteArray>("uid"); |
43 | keys << value; | ||
44 | }, | ||
45 | [](const Index::Error &error) { | ||
46 | Warning() << "Error in uid index: " << error.message; | ||
47 | }); | ||
48 | appliedFilters << "uid"; | ||
49 | } | 44 | } |
50 | Trace() << "Index lookup found " << keys.size() << " keys."; | 45 | return *index; |
51 | return ResultSet(keys); | 46 | } |
47 | |||
48 | ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) | ||
49 | { | ||
50 | return getIndex().query(query, appliedFilters, transaction); | ||
52 | } | 51 | } |
53 | 52 | ||
54 | void TypeImplementation<Event>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 53 | void TypeImplementation<Event>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
55 | { | 54 | { |
56 | const auto uid = bufferAdaptor.getProperty("uid"); | 55 | return getIndex().add(identifier, bufferAdaptor, transaction); |
57 | if (uid.isValid()) { | ||
58 | Index("event.index.uid", transaction).add(uid.toByteArray(), identifier); | ||
59 | } | ||
60 | } | 56 | } |
61 | 57 | ||
62 | void TypeImplementation<Event>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 58 | void TypeImplementation<Event>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
63 | { | 59 | { |
64 | const auto uid = bufferAdaptor.getProperty("uid"); | 60 | return getIndex().remove(identifier, bufferAdaptor, transaction); |
65 | if (uid.isValid()) { | ||
66 | Index("event.index.uid", transaction).remove(uid.toByteArray(), identifier); | ||
67 | } | ||
68 | } | 61 | } |
69 | 62 | ||
70 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() | 63 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() |