summaryrefslogtreecommitdiffstats
path: root/common/domain/folder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain/folder.cpp')
-rw-r--r--common/domain/folder.cpp47
1 files changed, 16 insertions, 31 deletions
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()