diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-19 10:29:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-19 11:15:19 +0200 |
commit | b940489ed6afe413339a1c602d05f3b4f3133463 (patch) | |
tree | 84b79d47236d83d2e6ae1833105885a885e4ce99 /common | |
parent | 077e3cb30ace5f6ee20ee15e0d32d2bfb197fde0 (diff) | |
download | sink-b940489ed6afe413339a1c602d05f3b4f3133463.tar.gz sink-b940489ed6afe413339a1c602d05f3b4f3133463.zip |
Asserts, debug messages and other cleanup
Diffstat (limited to 'common')
-rw-r--r-- | common/datastorequery.cpp | 1 | ||||
-rw-r--r-- | common/index.cpp | 1 | ||||
-rw-r--r-- | common/mailpreprocessor.cpp | 34 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 6 |
4 files changed, 20 insertions, 22 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: | |||
319 | //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. | 319 | //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. |
320 | QVariant reductionValue; | 320 | QVariant reductionValue; |
321 | readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { | 321 | readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { |
322 | Q_ASSERT(result.entity.identifier() == prev.identifier()); | ||
322 | reductionValue = prev.getProperty(mReductionProperty); | 323 | reductionValue = prev.getProperty(mReductionProperty); |
323 | }); | 324 | }); |
324 | return reductionValue; | 325 | 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 | |||
26 | 26 | ||
27 | void Index::add(const QByteArray &key, const QByteArray &value) | 27 | void Index::add(const QByteArray &key, const QByteArray &value) |
28 | { | 28 | { |
29 | Q_ASSERT(!key.isEmpty()); | ||
29 | mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) { | 30 | mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) { |
30 | SinkWarningCtx(mLogCtx) << "Error while writing value" << error; | 31 | SinkWarningCtx(mLogCtx) << "Error while writing value" << error; |
31 | }); | 32 | }); |
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 | |||
91 | mail.setExtractedBcc(getContactList(msg->bcc(true))); | 91 | mail.setExtractedBcc(getContactList(msg->bcc(true))); |
92 | mail.setExtractedDate(msg->date(true)->dateTime()); | 92 | mail.setExtractedDate(msg->date(true)->dateTime()); |
93 | 93 | ||
94 | //Ensure the mssageId is unique. | 94 | const auto parentMessageId = [&] { |
95 | //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. | 95 | //The last is the parent |
96 | 96 | auto references = msg->references(true)->identifiers(); | |
97 | //The last is the parent | 97 | |
98 | auto references = msg->references(true)->identifiers(); | 98 | //The first is the parent |
99 | 99 | auto inReplyTo = msg->inReplyTo(true)->identifiers(); | |
100 | //The first is the parent | 100 | |
101 | auto inReplyTo = msg->inReplyTo(true)->identifiers(); | 101 | if (!references.isEmpty()) { |
102 | QByteArray parentMessageId; | 102 | return references.last(); |
103 | if (!references.isEmpty()) { | 103 | //TODO we could use the rest of the references header to complete the ancestry in case we have missing parents. |
104 | parentMessageId = references.last(); | 104 | } else { |
105 | //TODO we could use the rest of the references header to complete the ancestry in case we have missing parents. | 105 | if (!inReplyTo.isEmpty()) { |
106 | } else { | 106 | //According to RFC5256 we should ignore all but the first |
107 | if (!inReplyTo.isEmpty()) { | 107 | return inReplyTo.first(); |
108 | //According to RFC5256 we should ignore all but the first | 108 | } |
109 | parentMessageId = inReplyTo.first(); | ||
110 | } | 109 | } |
111 | } | 110 | return QByteArray{}; |
111 | }(); | ||
112 | 112 | ||
113 | //The rest should never change, unless we didn't have the headers available initially. | 113 | //The rest should never change, unless we didn't have the headers available initially. |
114 | auto messageId = msg->messageID(true)->identifier(); | 114 | 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 | |||
249 | 249 | ||
250 | ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomainType ¤t, const ApplicationDomainType &diff, const QByteArrayList &deletions) const | 250 | ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomainType ¤t, const ApplicationDomainType &diff, const QByteArrayList &deletions) const |
251 | { | 251 | { |
252 | SinkTraceCtx(d->logCtx) << "Applying diff: " << current.availableProperties() << "Deletions: " << deletions << "Changeset: " << diff.changedProperties(); | ||
252 | auto newEntity = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(current, current.availableProperties()); | 253 | auto newEntity = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(current, current.availableProperties()); |
253 | 254 | ||
254 | SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; | ||
255 | |||
256 | // Apply diff | 255 | // Apply diff |
257 | //SinkTrace() << "Applying changed properties: " << changeset; | ||
258 | for (const auto &property : diff.changedProperties()) { | 256 | for (const auto &property : diff.changedProperties()) { |
259 | const auto value = diff.getProperty(property); | 257 | const auto value = diff.getProperty(property); |
260 | if (value.isValid()) { | 258 | if (value.isValid()) { |
261 | //SinkTrace() << "Setting property: " << property; | ||
262 | newEntity.setProperty(property, value); | 259 | newEntity.setProperty(property, value); |
263 | } | 260 | } |
264 | } | 261 | } |
265 | 262 | ||
266 | // Remove deletions | 263 | // Remove deletions |
267 | for (const auto &property : deletions) { | 264 | for (const auto &property : deletions) { |
268 | //SinkTrace() << "Removing property: " << property; | ||
269 | newEntity.setProperty(property, QVariant()); | 265 | newEntity.setProperty(property, QVariant()); |
270 | } | 266 | } |
271 | return newEntity; | 267 | return newEntity; |