mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2026-09-05 00:20:40 +00:00
Remove redundant entity cache
Progress towards #3989. May also help with #3235.
This commit is contained in:
@@ -300,7 +300,7 @@ class TelegramBaseClient(abc.ABC):
|
||||
self.flood_sleep_threshold = flood_sleep_threshold
|
||||
|
||||
# TODO Use AsyncClassWrapper(session)
|
||||
# ChatGetter and SenderGetter can use the in-memory _entity_cache
|
||||
# ChatGetter and SenderGetter can use the in-memory _mb_entity_cache
|
||||
# to avoid network access and the need for await in session files.
|
||||
#
|
||||
# The session files only wants the entities to persist
|
||||
@@ -308,7 +308,6 @@ class TelegramBaseClient(abc.ABC):
|
||||
# TODO Session should probably return all cached
|
||||
# info of entities, not just the input versions
|
||||
self.session = session
|
||||
self._entity_cache = EntityCache()
|
||||
self.api_id = int(api_id)
|
||||
self.api_hash = api_hash
|
||||
|
||||
@@ -433,7 +432,6 @@ class TelegramBaseClient(abc.ABC):
|
||||
self._catch_up = catch_up
|
||||
self._updates_queue = asyncio.Queue()
|
||||
self._message_box = MessageBox(self._log['messagebox'])
|
||||
# This entity cache is tailored for the messagebox and is not used for absolutely everything like _entity_cache
|
||||
self._mb_entity_cache = MbEntityCache() # required for proper update handling (to know when to getDifference)
|
||||
|
||||
self._sender = MTProtoSender(
|
||||
|
||||
@@ -72,7 +72,6 @@ class UserMethods:
|
||||
results.append(None)
|
||||
continue
|
||||
self.session.process_entities(result)
|
||||
self._entity_cache.add(result)
|
||||
exceptions.append(None)
|
||||
results.append(result)
|
||||
request_index += 1
|
||||
@@ -83,7 +82,6 @@ class UserMethods:
|
||||
else:
|
||||
result = await future
|
||||
self.session.process_entities(result)
|
||||
self._entity_cache.add(result)
|
||||
return result
|
||||
except (errors.ServerError, errors.RpcCallFailError,
|
||||
errors.RpcMcgetFailError, errors.InterdcCallErrorError,
|
||||
@@ -417,8 +415,8 @@ class UserMethods:
|
||||
try:
|
||||
# 0x2d45687 == crc32(b'Peer')
|
||||
if isinstance(peer, int) or peer.SUBCLASS_OF_ID == 0x2d45687:
|
||||
return self._entity_cache[peer]
|
||||
except (AttributeError, KeyError):
|
||||
return self._mb_entity_cache.get(utils.get_peer_id(peer, add_mark=False))._as_input_peer()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Then come known strings that take precedence
|
||||
|
||||
Reference in New Issue
Block a user