From b940489ed6afe413339a1c602d05f3b4f3133463 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 19 Jun 2018 10:29:20 +0200 Subject: Asserts, debug messages and other cleanup --- common/datastorequery.cpp | 1 + common/index.cpp | 1 + common/mailpreprocessor.cpp | 34 ++++++++++++++-------------- common/storage/entitystore.cpp | 6 +---- examples/maildirresource/maildirresource.cpp | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 263d3ea..0195cfc 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp @@ -319,6 +319,7 @@ public: //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. QVariant reductionValue; readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { + Q_ASSERT(result.entity.identifier() == prev.identifier()); reductionValue = prev.getProperty(mReductionProperty); }); return reductionValue; diff --git a/common/index.cpp b/common/index.cpp index 94b2eea..13ca6ed 100644 --- a/common/index.cpp +++ b/common/index.cpp @@ -26,6 +26,7 @@ Index::Index(const QByteArray &name, Sink::Storage::DataStore::Transaction &tran void Index::add(const QByteArray &key, const QByteArray &value) { + Q_ASSERT(!key.isEmpty()); mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(mLogCtx) << "Error while writing value" << error; }); diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp index 7bc80cd..3d5dc65 100644 --- a/common/mailpreprocessor.cpp +++ b/common/mailpreprocessor.cpp @@ -91,24 +91,24 @@ void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Ma mail.setExtractedBcc(getContactList(msg->bcc(true))); mail.setExtractedDate(msg->date(true)->dateTime()); - //Ensure the mssageId is unique. - //If there already is one with the same id we'd have to assign a new message id, which probably doesn't make any sense. - - //The last is the parent - auto references = msg->references(true)->identifiers(); - - //The first is the parent - auto inReplyTo = msg->inReplyTo(true)->identifiers(); - QByteArray parentMessageId; - if (!references.isEmpty()) { - parentMessageId = references.last(); - //TODO we could use the rest of the references header to complete the ancestry in case we have missing parents. - } else { - if (!inReplyTo.isEmpty()) { - //According to RFC5256 we should ignore all but the first - parentMessageId = inReplyTo.first(); + const auto parentMessageId = [&] { + //The last is the parent + auto references = msg->references(true)->identifiers(); + + //The first is the parent + auto inReplyTo = msg->inReplyTo(true)->identifiers(); + + if (!references.isEmpty()) { + return references.last(); + //TODO we could use the rest of the references header to complete the ancestry in case we have missing parents. + } else { + if (!inReplyTo.isEmpty()) { + //According to RFC5256 we should ignore all but the first + return inReplyTo.first(); + } } - } + return QByteArray{}; + }(); //The rest should never change, unless we didn't have the headers available initially. auto messageId = msg->messageID(true)->identifier(); diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 4fe7e3b..18c788a 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -249,23 +249,19 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomainType entity, bool ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomainType ¤t, const ApplicationDomainType &diff, const QByteArrayList &deletions) const { + SinkTraceCtx(d->logCtx) << "Applying diff: " << current.availableProperties() << "Deletions: " << deletions << "Changeset: " << diff.changedProperties(); auto newEntity = *ApplicationDomainType::getInMemoryRepresentation(current, current.availableProperties()); - SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; - // Apply diff - //SinkTrace() << "Applying changed properties: " << changeset; for (const auto &property : diff.changedProperties()) { const auto value = diff.getProperty(property); if (value.isValid()) { - //SinkTrace() << "Setting property: " << property; newEntity.setProperty(property, value); } } // Remove deletions for (const auto &property : deletions) { - //SinkTrace() << "Removing property: " << property; newEntity.setProperty(property, QVariant()); } return newEntity; diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 4c94d1d..f5a0fea 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -113,7 +113,7 @@ public: if (!maildir.isValid(true)) { SinkWarning() << "Maildir is not existing: " << path; } - SinkWarning() << "Storing message: " << data; + SinkTrace() << "Storing message: " << data; auto identifier = maildir.addEntry(data); return path + "/" + identifier; } -- cgit v1.2.3