summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/event.cpp35
-rw-r--r--common/domain/folder.cpp47
2 files changed, 30 insertions, 52 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
35using namespace Akonadi2::ApplicationDomain; 36using namespace Akonadi2::ApplicationDomain;
36 37
37ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) 38static 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
48ResultSet 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
54void TypeImplementation<Event>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) 53void 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
62void TypeImplementation<Event>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) 58void 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
70QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() 63QSharedPointer<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
35using namespace Akonadi2::ApplicationDomain; 36using namespace Akonadi2::ApplicationDomain;
36 37
37ResultSet TypeImplementation<Folder>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) 38static 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
49ResultSet 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
58void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) 54void 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
70void TypeImplementation<Folder>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) 60void 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
80QSharedPointer<ReadPropertyMapper<TypeImplementation<Folder>::Buffer> > TypeImplementation<Folder>::initializeReadPropertyMapper() 65QSharedPointer<ReadPropertyMapper<TypeImplementation<Folder>::Buffer> > TypeImplementation<Folder>::initializeReadPropertyMapper()