mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-27 08:36:27 +00:00
Refactor sqlite storage
This commit is contained in:
parent
8df8780841
commit
221f25dab0
@ -141,24 +141,29 @@ class SQLiteStorage(Storage):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def update_peers(self, peers: List[Tuple[int, int, str, List[str], str]]):
|
async def update_peers(self, peers: List[Tuple[int, int, str, List[str], str]]):
|
||||||
for peer_data in peers:
|
peers_data = []
|
||||||
id, access_hash, type, usernames, phone_number = peer_data
|
usernames_data = []
|
||||||
|
ids_to_delete = []
|
||||||
|
|
||||||
self.conn.execute(
|
for id, access_hash, type, usernames, phone_number in peers:
|
||||||
"REPLACE INTO peers (id, access_hash, type, phone_number)"
|
ids_to_delete.append((id,))
|
||||||
"VALUES (?, ?, ?, ?)",
|
peers_data.append((id, access_hash, type, phone_number))
|
||||||
(id, access_hash, type, phone_number)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.conn.execute(
|
if usernames:
|
||||||
"DELETE FROM usernames WHERE id = ?",
|
usernames_data.extend([(id, username) for username in usernames])
|
||||||
(id,)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
self.conn.executemany(
|
||||||
|
"REPLACE INTO peers (id, access_hash, type, phone_number) VALUES (?, ?, ?, ?)",
|
||||||
|
peers_data)
|
||||||
|
|
||||||
|
self.conn.executemany(
|
||||||
|
"DELETE FROM usernames WHERE id = ?",
|
||||||
|
ids_to_delete)
|
||||||
|
|
||||||
|
if usernames_data:
|
||||||
self.conn.executemany(
|
self.conn.executemany(
|
||||||
"REPLACE INTO usernames (id, username) VALUES (?, ?)",
|
"REPLACE INTO usernames (id, username) VALUES (?, ?)",
|
||||||
[(id, username) for username in usernames] if usernames else [(id, None)]
|
usernames_data)
|
||||||
)
|
|
||||||
|
|
||||||
async def update_state(self, value: Tuple[int, int, int, int, int] = object):
|
async def update_state(self, value: Tuple[int, int, int, int, int] = object):
|
||||||
if value == object:
|
if value == object:
|
||||||
|
Loading…
Reference in New Issue
Block a user