diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-19 11:00:39 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-19 12:27:01 +0200 |
commit | 49b83e87e4da54cdd18ec04b10fdb4624389bd80 (patch) | |
tree | d87a11bcb14e6ef3811df53c06aeb1726616a26c /common/mail/threadindexer.cpp | |
parent | b940489ed6afe413339a1c602d05f3b4f3133463 (diff) | |
download | sink-49b83e87e4da54cdd18ec04b10fdb4624389bd80.tar.gz sink-49b83e87e4da54cdd18ec04b10fdb4624389bd80.zip |
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.
Diffstat (limited to 'common/mail/threadindexer.cpp')
-rw-r--r-- | common/mail/threadindexer.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
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 @@ | |||
25 | using namespace Sink; | 25 | using namespace Sink; |
26 | using namespace Sink::ApplicationDomain; | 26 | using namespace Sink::ApplicationDomain; |
27 | 27 | ||
28 | void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction) | 28 | void ThreadIndexer::updateThreadingIndex(const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction) |
29 | { | 29 | { |
30 | auto messageId = entity.getProperty(Mail::MessageId::name); | 30 | auto messageId = entity.getProperty(Mail::MessageId::name); |
31 | auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); | 31 | auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); |
32 | if (messageId.toByteArray().isEmpty()) { | 32 | if (messageId.toByteArray().isEmpty()) { |
33 | SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << identifier; | 33 | SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << entity.identifier(); |
34 | } | 34 | } |
35 | 35 | ||
36 | QVector<QByteArray> thread; | 36 | SinkTrace() << "Indexing thread. Entity: " << entity.identifier() << "Messageid: " << messageId << "ParentMessageId: " << parentMessageId; |
37 | 37 | ||
38 | //check if a child already registered our thread. | 38 | //check if a child already registered our thread. |
39 | thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); | 39 | QVector<QByteArray> thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); |
40 | 40 | ||
41 | if (!thread.isEmpty()) { | 41 | if (!thread.isEmpty() && parentMessageId.isValid()) { |
42 | //A child already registered our thread so we merge the childs thread | 42 | //A child already registered our thread so we merge the childs thread |
43 | //* check if we have a parent thread, if not just continue as usual | 43 | //* check if we have a parent thread, if not just continue as usual |
44 | //* get all messages that have the same threadid as the child | 44 | //* get all messages that have the same threadid as the child |
45 | //* switch all to the parents thread | 45 | //* switch all to the parents thread |
46 | Q_ASSERT(!parentMessageId.toByteArray().isEmpty()); | ||
46 | auto parentThread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); | 47 | auto parentThread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); |
47 | if (!parentThread.isEmpty()) { | 48 | if (!parentThread.isEmpty()) { |
48 | auto childThreadId = thread.first(); | 49 | auto childThreadId = thread.first(); |
@@ -95,13 +96,22 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App | |||
95 | 96 | ||
96 | void ThreadIndexer::add(const ApplicationDomain::ApplicationDomainType &entity) | 97 | void ThreadIndexer::add(const ApplicationDomain::ApplicationDomainType &entity) |
97 | { | 98 | { |
98 | updateThreadingIndex(entity.identifier(), entity, transaction()); | 99 | updateThreadingIndex(entity, transaction()); |
100 | } | ||
101 | |||
102 | void ThreadIndexer::modify(const ApplicationDomain::ApplicationDomainType &oldEntity, const ApplicationDomain::ApplicationDomainType &newEntity) | ||
103 | { | ||
104 | //FIXME Implement to support thread changes. | ||
105 | //Emails are immutable (for everything threading relevant), so we don't care about it so far. | ||
99 | } | 106 | } |
100 | 107 | ||
101 | void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entity) | 108 | void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entity) |
102 | { | 109 | { |
103 | auto messageId = entity.getProperty(Mail::MessageId::name); | 110 | auto messageId = entity.getProperty(Mail::MessageId::name); |
104 | auto thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); | 111 | auto thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); |
112 | if (thread.isEmpty()) { | ||
113 | SinkWarning() << "Failed to find the threadId for the entity " << entity.identifier() << messageId; | ||
114 | } | ||
105 | index().unindex<Mail::MessageId, Mail::ThreadId>(messageId.toByteArray(), thread.first(), transaction()); | 115 | index().unindex<Mail::MessageId, Mail::ThreadId>(messageId.toByteArray(), thread.first(), transaction()); |
106 | index().unindex<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId.toByteArray(), transaction()); | 116 | index().unindex<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId.toByteArray(), transaction()); |
107 | } | 117 | } |