From 58a9bc81b0ee7f4dd19a2d8a6f690fb7440ee2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ar=C4=89i?= Date: Sat, 29 Oct 2022 17:56:00 +0600 Subject: [PATCH] use redis message cache for chat ids retrieval --- olgram/commands/bot_actions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/olgram/commands/bot_actions.py b/olgram/commands/bot_actions.py index f1f670a..8c03703 100644 --- a/olgram/commands/bot_actions.py +++ b/olgram/commands/bot_actions.py @@ -5,8 +5,9 @@ import asyncio from aiogram import types from aiogram.utils.exceptions import TelegramAPIError, Unauthorized from aiogram import Bot as AioBot -from olgram.models.models import Bot, User +from olgram.models.models import Bot from server.server import unregister_token +from server.custom import _redis from typing import Optional from locales.locale import _ @@ -93,7 +94,8 @@ async def start_broadcast(bot: Bot, call: types.CallbackQuery, text: Optional[st if not text: return await call.answer(_("Отправьте текст для рассылки")) - user_chat_ids = await User.all().values_list("telegram_id", flat=True) + keys = [key async for key in _redis.iscan(match=f"{bot.id}_*")] + user_chat_ids = await _redis.mget(*keys) a_bot = AioBot(bot.decrypted_token()) count = 0 await call.answer(_("Рассылка начата"))