Skip to content

Commit

Permalink
update throttling
Browse files Browse the repository at this point in the history
update dependencies
  • Loading branch information
taimast committed Jan 23, 2024
1 parent 9ef55ea commit 104f664
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
21 changes: 5 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,24 @@ authors = ["taimast <[email protected]>"]


[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"]
Expand Down
3 changes: 3 additions & 0 deletions src/apps/bot/callback_data/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions src/apps/bot/middlewares/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand All @@ -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)

0 comments on commit 104f664

Please sign in to comment.