From 49b83e87e4da54cdd18ec04b10fdb4624389bd80 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 19 Jun 2018 11:00:39 +0200 Subject: Fixed the thread index. * Modifications could result in index changes because we lost the threadId due to remove + add. A modify was necessary (although we can ignore it for the email case). * The ThreadIndexer would try to lookup and potentially index threads for empty parent ids, which is clearly wrong. --- common/mail/threadindexer.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'common/mail/threadindexer.cpp') diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp index fb47118..c1d1aa8 100644 --- a/common/mail/threadindexer.cpp +++ b/common/mail/threadindexer.cpp @@ -25,24 +25,25 @@ using namespace Sink; using namespace Sink::ApplicationDomain; -void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction) +void ThreadIndexer::updateThreadingIndex(const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction) { auto messageId = entity.getProperty(Mail::MessageId::name); auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); if (messageId.toByteArray().isEmpty()) { - SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << identifier; + SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << entity.identifier(); } - QVector thread; + SinkTrace() << "Indexing thread. Entity: " << entity.identifier() << "Messageid: " << messageId << "ParentMessageId: " << parentMessageId; //check if a child already registered our thread. - thread = index().secondaryLookup(messageId); + QVector thread = index().secondaryLookup(messageId); - if (!thread.isEmpty()) { + if (!thread.isEmpty() && parentMessageId.isValid()) { //A child already registered our thread so we merge the childs thread //* check if we have a parent thread, if not just continue as usual //* get all messages that have the same threadid as the child //* switch all to the parents thread + Q_ASSERT(!parentMessageId.toByteArray().isEmpty()); auto parentThread = index().secondaryLookup(parentMessageId); if (!parentThread.isEmpty()) { auto childThreadId = thread.first(); @@ -95,13 +96,22 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App void ThreadIndexer::add(const ApplicationDomain::ApplicationDomainType &entity) { - updateThreadingIndex(entity.identifier(), entity, transaction()); + updateThreadingIndex(entity, transaction()); +} + +void ThreadIndexer::modify(const ApplicationDomain::ApplicationDomainType &oldEntity, const ApplicationDomain::ApplicationDomainType &newEntity) +{ + //FIXME Implement to support thread changes. + //Emails are immutable (for everything threading relevant), so we don't care about it so far. } void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entity) { auto messageId = entity.getProperty(Mail::MessageId::name); auto thread = index().secondaryLookup(messageId); + if (thread.isEmpty()) { + SinkWarning() << "Failed to find the threadId for the entity " << entity.identifier() << messageId; + } index().unindex(messageId.toByteArray(), thread.first(), transaction()); index().unindex(thread.first(), messageId.toByteArray(), transaction()); } -- cgit v1.2.3