From 63290ccce102495427a26e689725e565a03ae77a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 27 Jul 2017 15:45:12 -0600 Subject: 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. --- common/domain/applicationdomaintype.cpp | 9 +++++++-- 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 void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) { Q_ASSERT(mAdaptor); - mChangeSet->insert(key); - mAdaptor->setProperty(key, value); + auto existing = mAdaptor->getProperty(key); + if (existing.isValid() && existing == value) { + SinkTrace() << "Tried to set property that is still the same: " << key << value; + } else { + mChangeSet->insert(key); + mAdaptor->setProperty(key, value); + } } 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 Store::create(const DomainType &domainObject) template KAsync::Job Store::modify(const DomainType &domainObject) { + if (domainObject.changedProperties().isEmpty()) { + SinkLog() << "Nothing to modify: " << domainObject.identifier(); + return KAsync::null(); + } SinkLog() << "Modify: " << domainObject; // Potentially move to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); @@ -218,6 +222,10 @@ KAsync::Job Store::modify(const DomainType &domainObject) template KAsync::Job Store::modify(const Query &query, const DomainType &domainObject) { + if (domainObject.changedProperties().isEmpty()) { + SinkLog() << "Nothing to modify: " << domainObject.identifier(); + return KAsync::null(); + } SinkLog() << "Modify: " << query << domainObject; return fetchAll(query) .each([=] (const typename DomainType::Ptr &entity) { -- cgit v1.2.3