summaryrefslogtreecommitdiffstats
path: root/common/typeindex.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-07 08:03:38 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-07 08:03:38 +0100
commit0279a63a420b89a5ac7287ff8cb2ba2ead0d9a83 (patch)
treeeb49a79ace9e5c16d29249f8478f9acef9bc01a4 /common/typeindex.cpp
parent4c20cc0d27295d2ea8661e8823c75821ef99f996 (diff)
downloadsink-0279a63a420b89a5ac7287ff8cb2ba2ead0d9a83.tar.gz
sink-0279a63a420b89a5ac7287ff8cb2ba2ead0d9a83.zip
Ported folder and event to TypeIndex
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r--common/typeindex.cpp28
1 files changed, 20 insertions, 8 deletions
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";