From d425436c268a748381f003646bd02e8d74ef7fba Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 10:41:48 +0200 Subject: Added draft property index. We need this for the composer to efficiently query. Since we don't have any migration code this will require all data to be refetched (sinksh upgrade). --- common/domain/typeimplementations.cpp | 1 + common/typeindex.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'common') diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp index 4e61bad..40b0cfd 100644 --- a/common/domain/typeimplementations.cpp +++ b/common/domain/typeimplementations.cpp @@ -41,6 +41,7 @@ typedef IndexConfig, ValueIndex, ValueIndex, + ValueIndex, SortedIndex, SecondaryIndex, SecondaryIndex, diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 3e66ffe..b8845b7 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp @@ -31,6 +31,10 @@ static QByteArray getByteArray(const QVariant &value) if (result.isEmpty()) { return "nodate"; } + return result; + } + if (value.type() == QVariant::Bool) { + return value.toBool() ? "t" : "f"; } if (value.canConvert()) { const auto ba = value.value().value; @@ -82,6 +86,20 @@ void TypeIndex::addProperty(const QByteArray &property) mProperties << property; } +template <> +void TypeIndex::addProperty(const QByteArray &property) +{ + auto indexer = [this, property](bool add, const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { + if (add) { + Index(indexName(property), transaction).add(getByteArray(value), identifier); + } else { + Index(indexName(property), transaction).remove(getByteArray(value), identifier); + } + }; + mIndexer.insert(property, indexer); + mProperties << property; +} + template <> void TypeIndex::addProperty(const QByteArray &property) { -- cgit v1.2.3