From f43bf141673485c472cbeeaa529e4856d08ef6c0 Mon Sep 17 00:00:00 2001 From: farkadi Date: Tue, 14 Jan 2025 23:59:08 +0700 Subject: [PATCH] Update --- src/api/auth_api.py | 11 ++++++++++- src/api/server_api.py | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/api/auth_api.py b/src/api/auth_api.py index fd2ba8c..aeb1df8 100644 --- a/src/api/auth_api.py +++ b/src/api/auth_api.py @@ -16,6 +16,8 @@ class AuthResult: class AuthAPI: def __init__(self): + # Кэшируем подключение + self._pool = None self.db_config = { 'host': '192.168.1.42', 'port': 3306, @@ -27,6 +29,12 @@ class AuthAPI: self.N = 0x894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7 self.g = 7 + async def get_pool(self): + """Получение или создание пула подключений""" + if self._pool is None: + self._pool = await aiomysql.create_pool(**self.db_config) + return self._pool + def _calculate_verifier(self, username: str, password: str, salt: bytes) -> bytes: """ Вычисляет верификатор для SRP6 @@ -50,7 +58,8 @@ class AuthAPI: async def login(self, username: str, password: str) -> AuthResult: try: - async with aiomysql.connect(**self.db_config) as conn: + pool = await self.get_pool() + async with pool.acquire() as conn: async with conn.cursor() as cur: # Получаем данные аккаунта await cur.execute(""" diff --git a/src/api/server_api.py b/src/api/server_api.py index 1d0489d..0c25a5a 100644 --- a/src/api/server_api.py +++ b/src/api/server_api.py @@ -17,8 +17,8 @@ class ServerAPI: def __init__(self): """Инициализация API для проверки статуса серверов""" # Настройки серверов - self.auth_address = ('178.159.92.167', 3724) - self.world_address = ('178.159.92.167', 8085) + self.auth_address = ('192.168.1.114', 3724) + self.world_address = ('192.168.1.114', 8085) # Настройки БД (только чтение) self.db_config = { 'host': '192.168.1.42',