Better get_input_entity code flow

Plenty of unnecessary exceptions were being raised and caught when
the input parameters were already correct. Furthermore, since
8abc7ade22, the in-disk cache was no
longer being used (so using usernames always reached out to memory).
This commit is contained in:
Lonami Exo
2019-04-03 09:36:58 +02:00
parent f95933c246
commit 22fcdeef7f
2 changed files with 23 additions and 13 deletions

View File

@@ -12,11 +12,12 @@ class EntityCache:
Adds the given entities to the cache, if they weren't saved before.
"""
if not utils.is_list_like(entities):
# Invariant: all "chats" and "users" are always iterables
# Invariant: all "chats" and "users" are always iterables,
# and "user" never is (so we wrap it inside a list).
entities = itertools.chain(
[getattr(entities, 'user', None)],
getattr(entities, 'chats', []),
getattr(entities, 'users', [])
getattr(entities, 'users', []),
(hasattr(entities, 'user') and [entities.user]) or []
)
for entity in entities: