From kde-commits Wed Nov 25 20:44:22 2009 From: =?utf-8?q?Aaron=20J=2E=20Seigo?= Date: Wed, 25 Nov 2009 20:44:22 +0000 To: kde-commits Subject: KDE/kdelibs/solid/solid/backends/hal Message-Id: <1259181862.143296.1346.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=125918187210572 SVN commit 1054295 by aseigo: if a property changes, don't invalidate the whole cache until we actually care about that item. this allows us to keep the cache hot when something irrelevant (to us) is changing behind our backs, resulting in even fewer dbus trips in those situations CCMAIL:kde-hardware-devel@kde.org M +39 -18 haldevice.cpp --- trunk/KDE/kdelibs/solid/solid/backends/hal/haldevice.cpp #1054294:1054295 @@ -105,10 +105,12 @@ "org.freedesktop.Hal.Device", QDBusConnection::systemBus()), cacheSynced(false), parent(0) { } + void checkCache(const QString &key = QString()); QDBusInterface device; QMap cache; QMap capListCache; + QSet invalidKeys; bool cacheSynced; HalDevice *parent; @@ -348,33 +350,47 @@ QVariant HalDevice::property(const QString &key) const { - return allProperties().value(key); + d->checkCache(key); + return d->cache.value(key); } -QMap HalDevice::allProperties() const +void HalDevicePrivate::checkCache(const QString &key) { - if (!d->cacheSynced) - { - QDBusReply reply = d->device.call("GetAllProperties"); - - if (reply.isValid()) { - d->cache = reply; - } else { - qWarning() << Q_FUNC_INFO << " error: " << reply.error().name() - << ", " << reply.error().message() << endl; - d->cache = QVariantMap(); + if (cacheSynced) { + if (key.isEmpty()) { + if (invalidKeys.isEmpty()) { + return; + } + } else if (!invalidKeys.contains(key)) { + return; } + } - d->cacheSynced = true; - //qDebug( )<< this << udi() << "failure"; + QDBusReply reply = device.call("GetAllProperties"); + + if (reply.isValid()) { + cache = reply; + } else { + qWarning() << Q_FUNC_INFO << " error: " << reply.error().name() + << ", " << reply.error().message() << endl; + cache = QVariantMap(); } + invalidKeys.clear(); + cacheSynced = true; + //qDebug( )<< q << udi() << "failure"; +} + +QMap HalDevice::allProperties() const +{ + d->checkCache(); return d->cache; } bool HalDevice::propertyExists(const QString &key) const { - return allProperties().value(key).isValid(); + d->checkCache(key); + return d->cache.value(key).isValid(); } bool HalDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const @@ -506,12 +522,17 @@ } result[key] = type; + d->cache.remove(key); + + if (d->cache.isEmpty()) { + d->cacheSynced = false; + d->invalidKeys.clear(); + } else { + d->invalidKeys.insert(key); + } } - d->cache.clear(); //qDebug() << this << "unsyncing the cache"; - d->cacheSynced = false; - emit propertyChanged(result); }