Make sessions async

SQLiteSession is not updated, don't try to use it
This commit is contained in:
Tulir Asokan
2021-12-20 18:52:02 +02:00
committed by Lonami Exo
parent 43f629f665
commit d2de0f3aca
9 changed files with 54 additions and 80 deletions

View File

@@ -255,7 +255,7 @@ class UpdateMethods:
state = d.intermediate_state
pts, date = state.pts, state.date
self._handle_update(types.Updates(
await self._handle_update(types.Updates(
users=d.users,
chats=d.chats,
date=state.date,
@@ -300,8 +300,8 @@ class UpdateMethods:
# It is important to not make _handle_update async because we rely on
# the order that the updates arrive in to update the pts and date to
# be always-increasing. There is also no need to make this async.
def _handle_update(self: 'TelegramClient', update):
self.session.process_entities(update)
async def _handle_update(self: 'TelegramClient', update):
await self.session.process_entities(update)
self._entity_cache.add(update)
if isinstance(update, (types.Updates, types.UpdatesCombined)):
@@ -372,7 +372,7 @@ class UpdateMethods:
# inserted because this is a rather expensive operation
# (default's sqlite3 takes ~0.1s to commit changes). Do
# it every minute instead. No-op if there's nothing new.
self.session.save()
await self.session.save()
# We need to send some content-related request at least hourly
# for Telegram to keep delivering updates, otherwise they will