From 15047128e56b97f0c6df4628f87e3653a754ad95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Thu, 12 Apr 2018 00:02:29 +0200 Subject: [PATCH 3/5] Avoid creating duplicate property entries in the cache Summary: Properties are associated with a specific interface, although the Solid UDisks2 backend merges properties from all interfaces into a single namespace. Fortunately most properties have either unique names accross interfaces, or are consistent (e.g. "Size" in org.fd.UDisks2.{Block,Partition}), thus this poses no problem in practice. QMap<>::unite(other) behaves like QMap<>::insertMulti(item), i.e. the map may contain multiple values per key, while QMap<>::insert(item) updates the value for existing keys. Test Plan: make solid-hardware list details Reviewers: #frameworks, broulik Reviewed By: broulik Subscribers: broulik Tags: #frameworks Differential Revision: https://phabricator.kde.org/D12124 --- src/solid/devices/backends/udisks2/udisksdevicebackend.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/solid/devices/backends/udisks2/udisksdevicebackend.cpp b/src/solid/devices/backends/udisks2/udisksdevicebackend.cpp index 69ebc72..def7dff 100644 --- a/src/solid/devices/backends/udisks2/udisksdevicebackend.cpp +++ b/src/solid/devices/backends/udisks2/udisksdevicebackend.cpp @@ -139,11 +139,15 @@ QVariantMap DeviceBackend::allProperties() const QDBusPendingReply reply = QDBusConnection::systemBus().call(call); if (reply.isValid()) { - m_propertyCache.unite(reply.value()); + auto props = reply.value(); + // Can not use QMap<>::unite(), as it allows multiple values per key + for (auto it = props.cbegin(); it != props.cend(); ++it) { + m_propertyCache.insert(it.key(), it.value()); + } } else { qWarning() << "Error getting props:" << reply.error().name() << reply.error().message(); } - //qDebug() << "After iface" << iface << ", cache now contains" << m_cache.size() << "items"; + //qDebug() << "After iface" << iface << ", cache now contains" << m_propertyCache.size() << "items"; } return m_propertyCache; -- 2.14.3