1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 04:22:07 +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
def get_all_allocated_sessions() -> list[SessionThpCache]:
def get_allocated_sessions(channel_id: bytes) -> list[SessionThpCache]:
if __debug__:
from trezor.utils import get_bytes_as_str
_list: list[SessionThpCache] = []
for session in _SESSIONS:
if _get_session_state(session) != _UNALLOCATED_STATE:
_list.append(session)
if __debug__:
log.debug(
__name__,
"session with channel_id: %s and session_id: %s is in ALLOCATED state",
get_bytes_as_str(session.channel_id),
get_bytes_as_str(session.session_id),
)
elif __debug__:
log.debug(__name__, "session %s is in UNALLOCATED state", str(session))
if _get_session_state(session) == _UNALLOCATED_STATE:
continue
if session.channel_id != channel_id:
continue
_list.append(session)
if __debug__:
log.debug(
__name__,
"session with channel_id: %s and session_id: %s is in ALLOCATED state",
get_bytes_as_str(session.channel_id),
get_bytes_as_str(session.session_id),
)
return _list

View File

@ -33,7 +33,7 @@ def load_cached_sessions(
if __debug__:
log.debug(__name__, "load_cached_sessions")
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__:
log.debug(
__name__,