1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 12:32:02 +00:00

feat(core): make loading sessions from cache faster

[no changelog]
This commit is contained in:
M1nd3r 2024-07-30 12:25:33 +02:00
parent e67781114c
commit 2b8a669619
2 changed files with 15 additions and 13 deletions

View File

@ -167,22 +167,24 @@ def get_all_allocated_channels() -> list[ChannelCache]:
return _list return _list
def get_all_allocated_sessions() -> list[SessionThpCache]: def get_allocated_sessions(channel_id: bytes) -> list[SessionThpCache]:
if __debug__: if __debug__:
from trezor.utils import get_bytes_as_str from trezor.utils import get_bytes_as_str
_list: list[SessionThpCache] = [] _list: list[SessionThpCache] = []
for session in _SESSIONS: for session in _SESSIONS:
if _get_session_state(session) != _UNALLOCATED_STATE: if _get_session_state(session) == _UNALLOCATED_STATE:
_list.append(session) continue
if __debug__: if session.channel_id != channel_id:
log.debug( continue
__name__, _list.append(session)
"session with channel_id: %s and session_id: %s is in ALLOCATED state", if __debug__:
get_bytes_as_str(session.channel_id), log.debug(
get_bytes_as_str(session.session_id), __name__,
) "session with channel_id: %s and session_id: %s is in ALLOCATED state",
elif __debug__: get_bytes_as_str(session.channel_id),
log.debug(__name__, "session %s is in UNALLOCATED state", str(session)) get_bytes_as_str(session.session_id),
)
return _list return _list

View File

@ -33,7 +33,7 @@ def load_cached_sessions(
if __debug__: if __debug__:
log.debug(__name__, "load_cached_sessions") log.debug(__name__, "load_cached_sessions")
sessions: dict[int, GenericSessionContext] = {} sessions: dict[int, GenericSessionContext] = {}
cached_sessions = cache_thp.get_all_allocated_sessions() cached_sessions = cache_thp.get_allocated_sessions(channel_ctx.channel_id)
if __debug__: if __debug__:
log.debug( log.debug(
__name__, __name__,