From b2243587a59b56224106e56a8c2bca54319a33ee Mon Sep 17 00:00:00 2001 From: mihalin Date: Thu, 26 May 2022 13:52:47 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B2=D0=B5=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B6=D0=B5=20=D1=81=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=8F=D0=B2=D1=88=D0=B8=D1=85=D1=81=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=B8=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- olgram/migrations/custom.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/olgram/migrations/custom.py b/olgram/migrations/custom.py index da1b3d4..87a8a20 100644 --- a/olgram/migrations/custom.py +++ b/olgram/migrations/custom.py @@ -1,7 +1,8 @@ """Наши собственные миграции, которые нельзя описать на языке SQL и с которыми не справится TortoiseORM/Aerich""" +import aioredis from tortoise import transactions, Tortoise -from olgram.settings import TORTOISE_ORM +from olgram.settings import TORTOISE_ORM, ServerSettings from olgram.models.models import MetaInfo, Bot import logging @@ -22,8 +23,21 @@ async def upgrade_1(): await meta_info.save() logging.info("done") + +async def upgrade_2(): + """Отменяем малый TTL для старых сообщений""" + + con = await aioredis.create_connection(ServerSettings.redis_path()) + client = aioredis.Redis(con) + + i, keys = await client.scan() + for key in keys: + if not key.startswith(b"thread"): + await client.pexpire(key, ServerSettings.redis_timeout_ms()) + + # Не забудь добавить миграцию в этот лист! -_migrations = [upgrade_1] +_migrations = [upgrade_1, upgrade_2] async def migrate():