diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-27 15:45:12 -0600 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-27 15:54:32 -0600 |
commit | 63290ccce102495427a26e689725e565a03ae77a (patch) | |
tree | c54f3b0c7d7bffa811a0e65abebddcc35a77de83 | |
parent | 5d197dec9dc8f5c8ef4acd72555c32108404c4ae (diff) | |
download | sink-63290ccce102495427a26e689725e565a03ae77a.tar.gz sink-63290ccce102495427a26e689725e565a03ae77a.zip |
Skip modifications that do nothing.
This allows us to i.e. blindly mark mails as read in kube, with the
modification automatically being dropped if it doesn't do anything
useful.
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 9 | ||||
-rw-r--r-- | common/store.cpp | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 2050fac..ee70c35 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -222,8 +222,13 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | |||
222 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) | 222 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) |
223 | { | 223 | { |
224 | Q_ASSERT(mAdaptor); | 224 | Q_ASSERT(mAdaptor); |
225 | mChangeSet->insert(key); | 225 | auto existing = mAdaptor->getProperty(key); |
226 | mAdaptor->setProperty(key, value); | 226 | if (existing.isValid() && existing == value) { |
227 | SinkTrace() << "Tried to set property that is still the same: " << key << value; | ||
228 | } else { | ||
229 | mChangeSet->insert(key); | ||
230 | mAdaptor->setProperty(key, value); | ||
231 | } | ||
227 | } | 232 | } |
228 | 233 | ||
229 | void ApplicationDomainType::setResource(const QByteArray &identifier) | 234 | void ApplicationDomainType::setResource(const QByteArray &identifier) |
diff --git a/common/store.cpp b/common/store.cpp index 392f9ce..33d7b51 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -209,6 +209,10 @@ KAsync::Job<void> Store::create(const DomainType &domainObject) | |||
209 | template <class DomainType> | 209 | template <class DomainType> |
210 | KAsync::Job<void> Store::modify(const DomainType &domainObject) | 210 | KAsync::Job<void> Store::modify(const DomainType &domainObject) |
211 | { | 211 | { |
212 | if (domainObject.changedProperties().isEmpty()) { | ||
213 | SinkLog() << "Nothing to modify: " << domainObject.identifier(); | ||
214 | return KAsync::null(); | ||
215 | } | ||
212 | SinkLog() << "Modify: " << domainObject; | 216 | SinkLog() << "Modify: " << domainObject; |
213 | // Potentially move to separate thread as well | 217 | // Potentially move to separate thread as well |
214 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 218 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
@@ -218,6 +222,10 @@ KAsync::Job<void> Store::modify(const DomainType &domainObject) | |||
218 | template <class DomainType> | 222 | template <class DomainType> |
219 | KAsync::Job<void> Store::modify(const Query &query, const DomainType &domainObject) | 223 | KAsync::Job<void> Store::modify(const Query &query, const DomainType &domainObject) |
220 | { | 224 | { |
225 | if (domainObject.changedProperties().isEmpty()) { | ||
226 | SinkLog() << "Nothing to modify: " << domainObject.identifier(); | ||
227 | return KAsync::null(); | ||
228 | } | ||
221 | SinkLog() << "Modify: " << query << domainObject; | 229 | SinkLog() << "Modify: " << query << domainObject; |
222 | return fetchAll<DomainType>(query) | 230 | return fetchAll<DomainType>(query) |
223 | .each([=] (const typename DomainType::Ptr &entity) { | 231 | .each([=] (const typename DomainType::Ptr &entity) { |