Clean-up client's __init__ and remove entity cache

Entity cache uses are removed. It was a source of ever-growing memory
usage that has to be reworked. This affects everything that tried to
obtain an input entity, input sender or input chat (such as the
SenderGetter or calls to _get_entity_pair). Input entities need to be
reworked in any case.

Its removal also affects the automatic cache of any raw API request.

Raise last error parameter is removed, and its behaviour made default.

The connection type parameter has been removed, since users really have
no need to change it.

A few more attributes have been made private, since users should not
mess with those.
This commit is contained in:
Lonami Exo
2022-01-18 12:52:22 +01:00
parent 85a9c13129
commit f8264abb5a
18 changed files with 104 additions and 253 deletions

View File

@@ -241,7 +241,7 @@ async def sign_in(
elif bot_token:
request = _tl.fn.auth.ImportBotAuthorization(
flags=0, bot_auth_token=bot_token,
api_id=self.api_id, api_hash=self.api_hash
api_id=self._api_id, api_hash=self._api_hash
)
else:
raise ValueError('You must provide either phone and code, password, or bot_token.')
@@ -313,8 +313,6 @@ async def _update_session_state(self, user, save=True):
Callback called whenever the login or sign up process completes.
Returns the input user parameter.
"""
self._authorized = True
state = await self(_tl.fn.updates.GetState())
await _replace_session_state(
self,
@@ -332,11 +330,11 @@ async def _update_session_state(self, user, save=True):
async def _replace_session_state(self, *, save=True, **changes):
new = dataclasses.replace(self._session_state, **changes)
await self.session.set_state(new)
await self._session.set_state(new)
self._session_state = new
if save:
await self.session.save()
await self._session.save()
async def send_code_request(
@@ -354,7 +352,7 @@ async def send_code_request(
else:
try:
result = await self(_tl.fn.auth.SendCode(
phone, self.api_id, self.api_hash, _tl.CodeSettings()))
phone, self._api_id, self._api_hash, _tl.CodeSettings()))
except errors.AuthRestartError:
return await self.send_code_request(phone)
@@ -377,7 +375,6 @@ async def log_out(self: 'TelegramClient') -> bool:
except errors.RPCError:
return False
self._authorized = False
self._state_cache.reset()
await self.disconnect()