diff options
-rw-r--r-- | common/domain/event.cpp | 35 | ||||
-rw-r--r-- | common/domain/folder.cpp | 47 | ||||
-rw-r--r-- | common/typeindex.cpp | 28 |
3 files changed, 50 insertions, 60 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() |
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 80e9f8f..3cd221e 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp | |||
@@ -29,52 +29,37 @@ | |||
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 "folder_generated.h" | 34 | #include "folder_generated.h" |
34 | 35 | ||
35 | using namespace Akonadi2::ApplicationDomain; | 36 | using namespace Akonadi2::ApplicationDomain; |
36 | 37 | ||
37 | ResultSet TypeImplementation<Folder>::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("parent")) { | 41 | if (!index) { |
41 | Index index("folder.index.parent", transaction); | 42 | index = new TypeIndex("folder"); |
42 | auto lookupKey = query.propertyFilter.value("parent").toByteArray(); | 43 | index->addProperty<QByteArray>("parent"); |
43 | if (lookupKey.isEmpty()) { | 44 | index->addProperty<QString>("name"); |
44 | lookupKey = "toplevel"; | ||
45 | } | ||
46 | index.lookup(lookupKey, [&](const QByteArray &value) { | ||
47 | keys << value; | ||
48 | }, | ||
49 | [](const Index::Error &error) { | ||
50 | Warning() << "Error in uid index: " << error.message; | ||
51 | }); | ||
52 | appliedFilters << "parent"; | ||
53 | } | 45 | } |
54 | Trace() << "Index lookup found " << keys.size() << " keys."; | 46 | return *index; |
55 | return ResultSet(keys); | 47 | } |
48 | |||
49 | ResultSet TypeImplementation<Folder>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) | ||
50 | { | ||
51 | return getIndex().query(query, appliedFilters, transaction); | ||
56 | } | 52 | } |
57 | 53 | ||
58 | void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 54 | void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
59 | { | 55 | { |
60 | const auto parent = bufferAdaptor.getProperty("parent"); | 56 | Trace() << "Indexing " << identifier; |
61 | Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); | 57 | getIndex().add(identifier, bufferAdaptor, transaction); |
62 | if (parent.isValid()) { | ||
63 | Q_ASSERT(!parent.toByteArray().isEmpty()); | ||
64 | Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); | ||
65 | } else { | ||
66 | Index("folder.index.parent", transaction).add("toplevel", identifier); | ||
67 | } | ||
68 | } | 58 | } |
69 | 59 | ||
70 | void TypeImplementation<Folder>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) | 60 | void TypeImplementation<Folder>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) |
71 | { | 61 | { |
72 | const auto parent = bufferAdaptor.getProperty("parent"); | 62 | getIndex().remove(identifier, bufferAdaptor, transaction); |
73 | if (parent.isValid()) { | ||
74 | Index("folder.index.parent", transaction).remove(parent.toByteArray(), identifier); | ||
75 | } else { | ||
76 | Index("folder.index.parent", transaction).remove("toplevel", identifier); | ||
77 | } | ||
78 | } | 63 | } |
79 | 64 | ||
80 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Folder>::Buffer> > TypeImplementation<Folder>::initializeReadPropertyMapper() | 65 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Folder>::Buffer> > TypeImplementation<Folder>::initializeReadPropertyMapper() |
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 0a0dc33..1e41267 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -32,7 +32,11 @@ void TypeIndex::addProperty<QByteArray>(const QByteArray &property) | |||
32 | { | 32 | { |
33 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { | 33 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { |
34 | // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 34 | // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); |
35 | Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); | 35 | if (value.isValid()) { |
36 | Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); | ||
37 | } else { | ||
38 | Index(mType + ".index." + property, transaction).add("toplevel", identifier); | ||
39 | } | ||
36 | }; | 40 | }; |
37 | mIndexer.insert(property, indexer); | 41 | mIndexer.insert(property, indexer); |
38 | mProperties << property; | 42 | mProperties << property; |
@@ -43,7 +47,11 @@ void TypeIndex::addProperty<QString>(const QByteArray &property) | |||
43 | { | 47 | { |
44 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { | 48 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { |
45 | // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 49 | // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); |
46 | Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); | 50 | if (value.isValid()) { |
51 | Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); | ||
52 | } else { | ||
53 | Index(mType + ".index." + property, transaction).add("toplevel", identifier); | ||
54 | } | ||
47 | }; | 55 | }; |
48 | mIndexer.insert(property, indexer); | 56 | mIndexer.insert(property, indexer); |
49 | mProperties << property; | 57 | mProperties << property; |
@@ -64,10 +72,8 @@ void TypeIndex::add(const QByteArray &identifier, const Akonadi2::ApplicationDom | |||
64 | { | 72 | { |
65 | for (const auto &property : mProperties) { | 73 | for (const auto &property : mProperties) { |
66 | const auto value = bufferAdaptor.getProperty(property); | 74 | const auto value = bufferAdaptor.getProperty(property); |
67 | if (value.isValid()) { | 75 | auto indexer = mIndexer.value(property); |
68 | auto indexer = mIndexer.value(property); | 76 | indexer(identifier, value, transaction); |
69 | indexer(identifier, value, transaction); | ||
70 | } | ||
71 | } | 77 | } |
72 | } | 78 | } |
73 | 79 | ||
@@ -78,6 +84,8 @@ void TypeIndex::remove(const QByteArray &identifier, const Akonadi2::Application | |||
78 | if (value.isValid()) { | 84 | if (value.isValid()) { |
79 | //FIXME don't always convert to byte array | 85 | //FIXME don't always convert to byte array |
80 | Index(mType + ".index." + property, transaction).remove(value.toByteArray(), identifier); | 86 | Index(mType + ".index." + property, transaction).remove(value.toByteArray(), identifier); |
87 | } else { | ||
88 | Index(mType + ".index." + property, transaction).remove("toplevel", identifier); | ||
81 | } | 89 | } |
82 | } | 90 | } |
83 | } | 91 | } |
@@ -88,7 +96,11 @@ ResultSet TypeIndex::query(const Akonadi2::Query &query, QSet<QByteArray> &appli | |||
88 | for (const auto &property : mProperties) { | 96 | for (const auto &property : mProperties) { |
89 | if (query.propertyFilter.contains(property)) { | 97 | if (query.propertyFilter.contains(property)) { |
90 | Index index(mType + ".index." + property, transaction); | 98 | Index index(mType + ".index." + property, transaction); |
91 | index.lookup(query.propertyFilter.value(property).toByteArray(), [&](const QByteArray &value) { | 99 | auto lookupKey = query.propertyFilter.value(property).toByteArray(); |
100 | if (lookupKey.isEmpty()) { | ||
101 | lookupKey = "toplevel"; | ||
102 | } | ||
103 | index.lookup(lookupKey, [&](const QByteArray &value) { | ||
92 | keys << value; | 104 | keys << value; |
93 | }, | 105 | }, |
94 | [property](const Index::Error &error) { | 106 | [property](const Index::Error &error) { |
@@ -96,7 +108,7 @@ ResultSet TypeIndex::query(const Akonadi2::Query &query, QSet<QByteArray> &appli | |||
96 | }); | 108 | }); |
97 | appliedFilters << property; | 109 | appliedFilters << property; |
98 | } | 110 | } |
99 | Trace() << "Index lookup found keys: " << keys.size(); | 111 | Trace() << "Index lookup on " << property << " found " << keys.size() << " keys."; |
100 | return ResultSet(keys); | 112 | return ResultSet(keys); |
101 | } | 113 | } |
102 | Trace() << "No matching index"; | 114 | Trace() << "No matching index"; |