Refactor code to utilize aiofiles for asynchronous file handling across multiple modules. Added a new function to remove blocked users from the database and updated user blocking/unblocking logic to use this new function. Improved database interaction in admin panel handlers by passing session objects instead of creating new connections. This enhances performance and maintains consistency in file operations.

This commit is contained in:
Zakhar Izmaylov
2025-01-23 06:34:45 +03:00
parent 1596c85bee
commit c4d3c921bd
8 changed files with 28 additions and 20 deletions
+13
View File
@@ -43,6 +43,19 @@ async def add_blocked_user(tg_id: int, conn: asyncpg.Connection):
)
async def remove_blocked_user(tg_id: int | list[int], conn: asyncpg.Connection):
"""
Удаляет пользователя или список пользователей из списка заблокированных.
:param tg_id: ID пользователя Telegram или список ID
:param conn: Подключение к базе данных
"""
if isinstance(tg_id, list):
await conn.execute("DELETE FROM blocked_users WHERE tg_id = ANY($1)", tg_id)
else:
await conn.execute("DELETE FROM blocked_users WHERE tg_id = $1", tg_id)
async def init_db(file_path: str = "assets/schema.sql"):
with open(file_path, mode="r") as file:
sql_content = file.read()