Skip to content

Reduce unnecessary Synchronous UPower DBus calls

Stefan Brüns requested to merge work/bruns/avoid_sync_dbus_upower_calls into master

The Solid::Battery instance is only required if the updated battery is a peripheral battery.

Determining if the battery belongs to a peripheral or is a power supply can be done in a significantly cheaper way using a lookup in the m_batteriesPercent and m_peripheralBatteriesPercent dictionaries.

Instantiating a Solid::Battery is fairly costly, as it will typically do a synchronous UPower DBus call.

Also delay the Solid::Battery instantiation until actually required.

The Device is only required when showing the notification, so do the trivial checks based on currentPercent/previousPercent first.

Edited by Stefan Brüns

Merge request reports