2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Remove threading.Lock usages

This commit is contained in:
Dan 2022-12-23 20:20:27 +01:00
parent ccb58f503c
commit 81573bce76

View File

@ -19,7 +19,6 @@
import inspect
import sqlite3
import time
from threading import Lock
from typing import List, Tuple, Any
from pyrogram import raw
@ -98,10 +97,9 @@ class SQLiteStorage(Storage):
super().__init__(name)
self.conn = None # type: sqlite3.Connection
self.lock = Lock()
def create(self):
with self.lock, self.conn:
with self.conn:
self.conn.executescript(SCHEMA)
self.conn.execute(
@ -119,24 +117,20 @@ class SQLiteStorage(Storage):
async def save(self):
await self.date(int(time.time()))
with self.lock:
self.conn.commit()
self.conn.commit()
async def close(self):
with self.lock:
self.conn.close()
self.conn.close()
async def delete(self):
raise NotImplementedError
async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
with self.lock:
self.conn.executemany(
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
"VALUES (?, ?, ?, ?, ?)",
peers
)
self.conn.executemany(
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
"VALUES (?, ?, ?, ?, ?)",
peers
)
async def get_peer_by_id(self, peer_id: int):
r = self.conn.execute(
@ -185,7 +179,7 @@ class SQLiteStorage(Storage):
def _set(self, value: Any):
attr = inspect.stack()[2].function
with self.lock, self.conn:
with self.conn:
self.conn.execute(
f"UPDATE sessions SET {attr} = ?",
(value,)
@ -221,7 +215,7 @@ class SQLiteStorage(Storage):
"SELECT number FROM version"
).fetchone()[0]
else:
with self.lock, self.conn:
with self.conn:
self.conn.execute(
"UPDATE version SET number = ?",
(value,)