1
0

hw DeviceMgr: speed-up client_for_keystore() for common-case

This method is often called when there is already an existing paired
client for the keystore, in which case we can avoid scan_devices() -
which would needlessly take several seconds.
This commit is contained in:
SomberNight
2022-12-19 08:31:04 +00:00
parent a4276102f2
commit d821e26f6e

View File

@@ -511,10 +511,16 @@ class DeviceMgr(ThreadJob):
if handler is None: if handler is None:
raise Exception(_("Handler not found for") + ' ' + plugin.name + '\n' + _("A library is probably missing.")) raise Exception(_("Handler not found for") + ' ' + plugin.name + '\n' + _("A library is probably missing."))
handler.update_status(False) handler.update_status(False)
if devices is None: pcode = keystore.pairing_code()
devices = self.scan_devices() client = None
client = self.client_by_pairing_code( # search existing clients first (fast-path)
plugin=plugin, pairing_code=keystore.pairing_code(), handler=handler, devices=devices) if not devices:
client = self.client_by_pairing_code(plugin=plugin, pairing_code=pcode, handler=handler, devices=[])
# search clients again, now allowing a (slow) scan
if client is None:
if devices is None:
devices = self.scan_devices()
client = self.client_by_pairing_code(plugin=plugin, pairing_code=pcode, handler=handler, devices=devices)
if client is None and force_pair: if client is None and force_pair:
try: try:
info = self.select_device(plugin, handler, keystore, devices, info = self.select_device(plugin, handler, keystore, devices,