From d2121c76cbb6db4574f9ef3e88ecb96c891f3a02 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 29 Dec 2017 19:41:12 +0100 Subject: [PATCH] Fetch and persist each auth_key per DC --- telethon/tl/session.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/telethon/tl/session.py b/telethon/tl/session.py index 193c6d44..8c2850bf 100644 --- a/telethon/tl/session.py +++ b/telethon/tl/session.py @@ -168,6 +168,17 @@ class Session: self._port = port self._update_session_table() + # Fetch the auth_key corresponding to this data center + c = self._conn.cursor() + c.execute('select auth_key from sessions') + tuple_ = c.fetchone() + if tuple_: + from ..crypto import AuthKey + self._auth_key = AuthKey(data=tuple_[0]) + else: + self._auth_key = None + c.close() + @property def server_address(self): return self._server_address @@ -188,8 +199,7 @@ class Session: def _update_session_table(self): with self._db_lock: c = self._conn.cursor() - c.execute('delete from sessions') - c.execute('insert into sessions values (?,?,?,?)', ( + c.execute('insert or replace into sessions values (?,?,?,?)', ( self._dc_id, self._server_address, self._port,