Desktop: Improve DeviceInfo caching

This commit is contained in:
Dain Nilsson 2024-08-28 11:12:23 +02:00
parent 848605c855
commit a35875a51e
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 18 additions and 6 deletions

View File

@ -274,9 +274,6 @@ class AbstractDeviceNode(RpcNode):
# Clear DeviceInfo cache
self._info = None
self._data = None
# Make sure any child node is re-opened after this,
# as enabled applications may have changed
super().close()
return response
@ -465,7 +462,20 @@ class ConnectionNode(RpcNode):
def __call__(self, *args, **kwargs):
try:
return super().__call__(*args, **kwargs)
response = super().__call__(*args, **kwargs)
if "device_info" in response.flags:
# Refresh DeviceInfo
info = read_info(self._connection, self._device.pid)
if self._info != info:
self._info = info
# Make sure any child node is re-opened after this,
# as enabled applications may have changed
self.close()
else:
# No change to DeviceInfo, further propagation not needed.
response.flags.remove("device_info")
return response
except (SmartcardException, OSError) as e:
logger.exception("Connection error")
raise ChildResetException(f"{e}")

View File

@ -502,7 +502,7 @@ class SlotNode(RpcNode):
self._refresh()
return dict(
response = dict(
metadata=_metadata_dict(metadata),
public_key=(
private_key.public_key()
@ -519,6 +519,7 @@ class SlotNode(RpcNode):
else None
),
)
return RpcResponse(response, ["device_info"])
@action
def generate(self, params, event, signal):
@ -570,4 +571,5 @@ class SlotNode(RpcNode):
self._refresh()
return dict(public_key=public_key_pem, result=result)
response = dict(public_key=public_key_pem, result=result)
return RpcResponse(response, ["device_info"])