summaryrefslogtreecommitdiffstats
path: root/common/typeindex.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-22 18:22:39 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-22 18:22:39 +0100
commitb2ad8f785e801a35cadf254d827f56d648be510c (patch)
tree4eeb1e3eefb02c40dac40469c0fae5ad91feb3e3 /common/typeindex.cpp
parent1fe8664ec74165fc3f250098609ea0e049e3adc8 (diff)
downloadsink-b2ad8f785e801a35cadf254d827f56d648be510c.tar.gz
sink-b2ad8f785e801a35cadf254d827f56d648be510c.zip
Introduced Log::Context
To have hierarchical debug output we have to pass around something at run-time, there is no reasonable alternative. Log::Context provides the identifier to do just that and largely replaces the debug component idea.
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r--common/typeindex.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/common/typeindex.cpp b/common/typeindex.cpp
index 9d71463..077bfa1 100644
--- a/common/typeindex.cpp
+++ b/common/typeindex.cpp
@@ -57,7 +57,7 @@ static QByteArray toSortableByteArray(const QDateTime &date)
57} 57}
58 58
59 59
60TypeIndex::TypeIndex(const QByteArray &type) : mType(type) 60TypeIndex::TypeIndex(const QByteArray &type, const Sink::Log::Context &ctx) : mLogCtx(ctx), mType(type)
61{ 61{
62} 62}
63 63
@@ -73,7 +73,7 @@ template <>
73void TypeIndex::addProperty<QByteArray>(const QByteArray &property) 73void TypeIndex::addProperty<QByteArray>(const QByteArray &property)
74{ 74{
75 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { 75 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) {
76 // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); 76 // SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << value.toByteArray();
77 Index(indexName(property), transaction).add(getByteArray(value), identifier); 77 Index(indexName(property), transaction).add(getByteArray(value), identifier);
78 }; 78 };
79 mIndexer.insert(property, indexer); 79 mIndexer.insert(property, indexer);
@@ -84,7 +84,7 @@ template <>
84void TypeIndex::addProperty<QString>(const QByteArray &property) 84void TypeIndex::addProperty<QString>(const QByteArray &property)
85{ 85{
86 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { 86 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) {
87 // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); 87 // SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << value.toByteArray();
88 Index(indexName(property), transaction).add(getByteArray(value), identifier); 88 Index(indexName(property), transaction).add(getByteArray(value), identifier);
89 }; 89 };
90 mIndexer.insert(property, indexer); 90 mIndexer.insert(property, indexer);
@@ -95,7 +95,7 @@ template <>
95void TypeIndex::addProperty<QDateTime>(const QByteArray &property) 95void TypeIndex::addProperty<QDateTime>(const QByteArray &property)
96{ 96{
97 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { 97 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) {
98 //SinkTrace() << "Indexing " << mType + ".index." + property << getByteArray(value); 98 //SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << getByteArray(value);
99 Index(indexName(property), transaction).add(getByteArray(value), identifier); 99 Index(indexName(property), transaction).add(getByteArray(value), identifier);
100 }; 100 };
101 mIndexer.insert(property, indexer); 101 mIndexer.insert(property, indexer);
@@ -182,7 +182,7 @@ QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArr
182 keys << indexLookup(index, query.getFilter(it.key())); 182 keys << indexLookup(index, query.getFilter(it.key()));
183 appliedFilters << it.key(); 183 appliedFilters << it.key();
184 appliedSorting = it.value(); 184 appliedSorting = it.value();
185 SinkTrace() << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys."; 185 SinkTraceCtx(mLogCtx) << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys.";
186 return keys; 186 return keys;
187 } 187 }
188 } 188 }
@@ -191,24 +191,24 @@ QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArr
191 Index index(indexName(property), transaction); 191 Index index(indexName(property), transaction);
192 keys << indexLookup(index, query.getFilter(property)); 192 keys << indexLookup(index, query.getFilter(property));
193 appliedFilters << property; 193 appliedFilters << property;
194 SinkTrace() << "Index lookup on " << property << " found " << keys.size() << " keys."; 194 SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys.";
195 return keys; 195 return keys;
196 } 196 }
197 } 197 }
198 SinkTrace() << "No matching index"; 198 SinkTraceCtx(mLogCtx) << "No matching index";
199 return keys; 199 return keys;
200} 200}
201 201
202QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) 202QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction)
203{ 203{
204 SinkTrace() << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; 204 SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties;
205 if (mProperties.contains(property)) { 205 if (mProperties.contains(property)) {
206 QVector<QByteArray> keys; 206 QVector<QByteArray> keys;
207 Index index(indexName(property), transaction); 207 Index index(indexName(property), transaction);
208 const auto lookupKey = getByteArray(value); 208 const auto lookupKey = getByteArray(value);
209 index.lookup( 209 index.lookup(
210 lookupKey, [&, this](const QByteArray &value) { keys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); 210 lookupKey, [&, this](const QByteArray &value) { keys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; });
211 SinkTrace() << "Index lookup on " << property << " found " << keys.size() << " keys."; 211 SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys.";
212 return keys; 212 return keys;
213 } else if (mSecondaryProperties.contains(property)) { 213 } else if (mSecondaryProperties.contains(property)) {
214 //Lookups on secondary indexes first lookup the key, and then lookup the results again to resolve to entity id's 214 //Lookups on secondary indexes first lookup the key, and then lookup the results again to resolve to entity id's
@@ -220,7 +220,7 @@ QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant
220 const auto lookupKey = getByteArray(value); 220 const auto lookupKey = getByteArray(value);
221 index.lookup( 221 index.lookup(
222 lookupKey, [&, this](const QByteArray &value) { secondaryKeys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); 222 lookupKey, [&, this](const QByteArray &value) { secondaryKeys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; });
223 SinkTrace() << "Looked up secondary keys: " << secondaryKeys; 223 SinkTraceCtx(mLogCtx) << "Looked up secondary keys: " << secondaryKeys;
224 for (const auto &secondary : secondaryKeys) { 224 for (const auto &secondary : secondaryKeys) {
225 keys += lookup(resultProperty, secondary, transaction); 225 keys += lookup(resultProperty, secondary, transaction);
226 } 226 }