From 04922fee3cebccd1bf3b99b367db119f7e129680 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 23 Apr 2025 19:21:36 +0200 Subject: [PATCH] Stop re-saving input peers on disconnect This was overwriting actual information on the cache. --- telethon/_updates/entitycache.py | 3 --- telethon/client/telegrambaseclient.py | 8 ++------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/telethon/_updates/entitycache.py b/telethon/_updates/entitycache.py index fd56c3e1..6973599e 100644 --- a/telethon/_updates/entitycache.py +++ b/telethon/_updates/entitycache.py @@ -49,9 +49,6 @@ class EntityCache: if getattr(c, 'access_hash', None) and not getattr(c, 'min', None) ) - def get_all_entities(self): - return [Entity(ty, id, hash) for id, (hash, ty) in self.hash_map.items()] - def put(self, entity): self.hash_map[entity.id] = (entity.hash, entity.ty) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 95c28532..77768b78 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -687,14 +687,10 @@ class TelegramBaseClient(abc.ABC): connection._proxy = proxy def _save_states_and_entities(self: 'TelegramClient'): - entities = self._mb_entity_cache.get_all_entities() - - # Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities. - # It doesn't matter if we put users in the list of chats. - self.session.process_entities(types.contacts.ResolvedPeer(None, [e._as_input_peer() for e in entities], [])) - # As a hack to not need to change the session files, save ourselves with ``id=0`` and ``access_hash`` of our ``id``. # This way it is possible to determine our own ID by querying for 0. However, whether we're a bot is not saved. + # Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities. + # It doesn't matter if we put users in the list of chats. if self._mb_entity_cache.self_id: self.session.process_entities(types.contacts.ResolvedPeer(None, [types.InputPeerUser(0, self._mb_entity_cache.self_id)], []))