summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-06-19 10:29:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-06-19 11:15:19 +0200
commitb940489ed6afe413339a1c602d05f3b4f3133463 (patch)
tree84b79d47236d83d2e6ae1833105885a885e4ce99
parent077e3cb30ace5f6ee20ee15e0d32d2bfb197fde0 (diff)
downloadsink-b940489ed6afe413339a1c602d05f3b4f3133463.tar.gz
sink-b940489ed6afe413339a1c602d05f3b4f3133463.zip
Asserts, debug messages and other cleanup
-rw-r--r--common/datastorequery.cpp1
-rw-r--r--common/index.cpp1
-rw-r--r--common/mailpreprocessor.cpp34
-rw-r--r--common/storage/entitystore.cpp6
-rw-r--r--examples/maildirresource/maildirresource.cpp2
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:
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
27void Index::add(const QByteArray &key, const QByteArray &value) 27void 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
250ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomainType &current, const ApplicationDomainType &diff, const QByteArrayList &deletions) const 250ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomainType &current, 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;
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:
113 if (!maildir.isValid(true)) { 113 if (!maildir.isValid(true)) {
114 SinkWarning() << "Maildir is not existing: " << path; 114 SinkWarning() << "Maildir is not existing: " << path;
115 } 115 }
116 SinkWarning() << "Storing message: " << data; 116 SinkTrace() << "Storing message: " << data;
117 auto identifier = maildir.addEntry(data); 117 auto identifier = maildir.addEntry(data);
118 return path + "/" + identifier; 118 return path + "/" + identifier;
119 } 119 }