Improve TakeoutClient proxy and takeout functionality (#1106)

This commit is contained in:
Dmitry D. Chernov
2019-02-10 20:10:41 +10:00
committed by Lonami
parent 274fa72a8c
commit 9a98d41a2c
6 changed files with 153 additions and 51 deletions

View File

@@ -18,7 +18,7 @@ except ImportError:
sqlite3 = None
EXTENSION = '.session'
CURRENT_VERSION = 4 # database version
CURRENT_VERSION = 5 # database version
class SQLiteSession(MemorySession):
@@ -65,7 +65,8 @@ class SQLiteSession(MemorySession):
c.execute('select * from sessions')
tuple_ = c.fetchone()
if tuple_:
self._dc_id, self._server_address, self._port, key, = tuple_
self._dc_id, self._server_address, self._port, key, \
self._takeout_id = tuple_
self._auth_key = AuthKey(data=key)
c.close()
@@ -79,7 +80,8 @@ class SQLiteSession(MemorySession):
dc_id integer primary key,
server_address text,
port integer,
auth_key blob
auth_key blob,
takeout_id integer
)"""
,
"""entities (
@@ -172,6 +174,9 @@ class SQLiteSession(MemorySession):
date integer,
seq integer
)""")
if old == 4:
old += 1
c.execute("alter table sessions add column takeout_id integer")
c.close()
@staticmethod
@@ -197,6 +202,11 @@ class SQLiteSession(MemorySession):
self._auth_key = value
self._update_session_table()
@MemorySession.takeout_id.setter
def takeout_id(self, value):
self._takeout_id = value
self._update_session_table()
def _update_session_table(self):
c = self._cursor()
# While we can save multiple rows into the sessions table
@@ -205,11 +215,12 @@ class SQLiteSession(MemorySession):
# some more work before being able to save auth_key's for
# multiple DCs. Probably done differently.
c.execute('delete from sessions')
c.execute('insert or replace into sessions values (?,?,?,?)', (
c.execute('insert or replace into sessions values (?,?,?,?,?)', (
self._dc_id,
self._server_address,
self._port,
self._auth_key.key if self._auth_key else b''
self._auth_key.key if self._auth_key else b'',
self._takeout_id
))
c.close()