From 104f664c3031c38ea8fb0e53bbc242bc50b6d7d5 Mon Sep 17 00:00:00 2001 From: taimast Date: Tue, 23 Jan 2024 06:40:35 +0300 Subject: [PATCH] update throttling update dependencies --- pyproject.toml | 21 +++++---------------- src/apps/bot/callback_data/paginator.py | 3 +++ src/apps/bot/middlewares/throttling.py | 16 ++-------------- 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 083ca3d..61bb0b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,35 +6,24 @@ authors = ["taimast "] [tool.poetry.dependencies] -python = "^3.11" +python = ">=3.11,<4.0" loguru = "^0.7.0" PyYAML = "^6.0" -APScheduler = {version = "^4.0.0a3", allow-prereleases = true} -cachetools = "^5.2.0" +aiogram = {version = "^3.3.0", allow-prereleases = true} +APScheduler = {version = "^4.0.0a4", allow-prereleases = true} pydantic = "^2.0.3" -aiogram = { version = "^3", allow-prereleases = true } fluentogram = "^1.1.6" sqlalchemy = "^2.0.9" -asyncpg = "^0.27.0" psycopg2 = "^2.9.6" -pre-commit = "^3.3.2" aiosqlite = "^0.19.0" pydantic-settings = "^2.0.2" -bs4 = "^0.0.1" -lxml = "^4.9.3" alembic = "^1.13.0" -fabric = "^3.2.2" [tool.poetry.group.utils.dependencies] -watchdog = "^3.0.0" -sqlalchemy-utils = "^0.41.1" [tool.poetry.group.dev.dependencies] -jinja2 = "^3.1.2" -pygithub = "^1.58.1" -invocations = "^3.1.0" -asyncache = "^0.3.1" -openai = "^1.6.1" +watchdog = "^3.0.0" +sqlalchemy-utils = "^0.41.1" [tool.poetry.extras] qiwi = ["glqiwiapi"] diff --git a/src/apps/bot/callback_data/paginator.py b/src/apps/bot/callback_data/paginator.py index 6a7dede..f513433 100644 --- a/src/apps/bot/callback_data/paginator.py +++ b/src/apps/bot/callback_data/paginator.py @@ -54,6 +54,9 @@ def has_next(self, length: int, page: int = 0) -> bool: def slice(self, items: Sequence[T]) -> Sequence[T]: return items[self.offset:self.offset + self.limit] + def slice_first(self, items: Sequence[T]) -> T: + return self.slice(items)[0] + def sort(self, items: list[T], key: Callable[[T], Any]) -> list[T]: if not self.sort_order: return items diff --git a/src/apps/bot/middlewares/throttling.py b/src/apps/bot/middlewares/throttling.py index 2e054af..07107fd 100644 --- a/src/apps/bot/middlewares/throttling.py +++ b/src/apps/bot/middlewares/throttling.py @@ -6,14 +6,8 @@ class ThrottlingMiddleware(BaseMiddleware): - # caches = { - # "spin": TTLCache(maxsize=10_000, ttl=THROTTLE_TIME_SPIN), - # "default": TTLCache(maxsize=10_000, ttl=THROTTLE_TIME_OTHER) - # } - # cache = TTLCache(maxsize=10_000, ttl=10) - def __init__(self, ttl: float = 10) -> None: - self.cache = TTLCache(maxsize=10_000, ttl=ttl) + self.cache:TTLCache[int, bool] = TTLCache(maxsize=10_000, ttl=ttl) async def __call__(self, handler: Callable[[Update, Dict[str, Any]], Awaitable[Any]], @@ -22,12 +16,6 @@ async def __call__(self, user = data.get('event_from_user') if user.id in self.cache: return + self.cache[user.id] = True return await handler(event, data) - # throttling_key = get_flag(data, "throttling_key") - # if throttling_key is not None and throttling_key in self.caches: - # if event.chat.id in self.caches[throttling_key]: - # return - # else: - # self.caches[throttling_key][event.chat.id] = None - # return await handler(event, data)