mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-05-05 04:16:17 +00:00
@@ -797,7 +797,7 @@ async def get_server_ids_by_uuids(
|
||||
db: AsyncSession,
|
||||
squad_uuids: List[str]
|
||||
) -> List[int]:
|
||||
|
||||
|
||||
result = await db.execute(
|
||||
select(ServerSquad.id)
|
||||
.where(ServerSquad.squad_uuid.in_(squad_uuids))
|
||||
@@ -805,6 +805,21 @@ async def get_server_ids_by_uuids(
|
||||
return [row[0] for row in result.fetchall()]
|
||||
|
||||
|
||||
async def get_server_squads_by_uuids(
|
||||
db: AsyncSession,
|
||||
squad_uuids: List[str]
|
||||
) -> List[ServerSquad]:
|
||||
"""Получает список ServerSquad объектов по их UUID."""
|
||||
if not squad_uuids:
|
||||
return []
|
||||
|
||||
result = await db.execute(
|
||||
select(ServerSquad)
|
||||
.where(ServerSquad.squad_uuid.in_(squad_uuids))
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def ensure_servers_synced(db: AsyncSession) -> None:
|
||||
"""
|
||||
Проверяет и синхронизирует серверы при запуске.
|
||||
|
||||
@@ -284,12 +284,18 @@ class MonitoringService:
|
||||
if not user or not user.remnawave_uuid:
|
||||
logger.error(f"RemnaWave UUID не найден для пользователя {subscription.user_id}")
|
||||
return None
|
||||
|
||||
|
||||
# Обновляем subscription в сессии, чтобы избежать detached instance
|
||||
try:
|
||||
await db.refresh(subscription)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
current_time = datetime.utcnow()
|
||||
is_active = (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
is_active = (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
subscription.end_date > current_time)
|
||||
|
||||
if (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
|
||||
if (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
subscription.end_date <= current_time):
|
||||
subscription.status = SubscriptionStatus.EXPIRED.value
|
||||
await db.commit()
|
||||
|
||||
@@ -320,11 +320,17 @@ class SubscriptionService:
|
||||
if not user or not user.remnawave_uuid:
|
||||
logger.error(f"RemnaWave UUID не найден для пользователя {subscription.user_id}")
|
||||
return None
|
||||
|
||||
|
||||
# Загружаем tariff заранее, чтобы избежать lazy loading в async контексте
|
||||
try:
|
||||
await db.refresh(subscription, ["tariff"])
|
||||
except Exception:
|
||||
pass # tariff может быть None или уже загружен
|
||||
|
||||
current_time = datetime.utcnow()
|
||||
is_actually_active = (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
is_actually_active = (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
subscription.end_date > current_time)
|
||||
|
||||
|
||||
if (subscription.status == SubscriptionStatus.ACTIVE.value and
|
||||
subscription.end_date <= current_time):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user