From 1ef92b9d681e614d65b0ca0a2abdfd81a943e778 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 May 2017 13:30:34 +0200 Subject: Added threading index cleanup --- common/mail/threadindexer.cpp | 5 ++++- common/typeindex.cpp | 12 ++++++++++++ common/typeindex.h | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp index ea2cf71..4171d85 100644 --- a/common/mail/threadindexer.cpp +++ b/common/mail/threadindexer.cpp @@ -71,7 +71,10 @@ void ThreadIndexer::modify(const ApplicationDomain::ApplicationDomainType &old, void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entity) { - + auto messageId = entity.getProperty(Mail::MessageId::name); + auto thread = index().secondaryLookup(messageId); + index().unindex(messageId.toByteArray(), thread.first(), transaction()); + index().unindex(thread.first(), messageId.toByteArray(), transaction()); } QMap ThreadIndexer::databases() diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 113c209..5a19839 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp @@ -281,6 +281,18 @@ void TypeIndex::index(const QByteArray &leftName, const QBy Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); } +template <> +void TypeIndex::unindex(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) +{ + Index(indexName(leftName + rightName), transaction).remove(getByteArray(leftValue), getByteArray(rightValue)); +} + +template <> +void TypeIndex::unindex(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) +{ + Index(indexName(leftName + rightName), transaction).remove(getByteArray(leftValue), getByteArray(rightValue)); +} + template <> QVector TypeIndex::secondaryLookup(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value) { diff --git a/common/typeindex.h b/common/typeindex.h index 1f216a7..890c3db 100644 --- a/common/typeindex.h +++ b/common/typeindex.h @@ -95,6 +95,15 @@ public: template void index(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction); + template + void unindex(const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) + { + index(Left::name, Right::name, leftValue, rightValue, transaction); + } + + template + void unindex(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction); + private: friend class Sink::Storage::EntityStore; -- cgit v1.2.3