Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/backend/app/guards/rate_limit.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import inspect
from time import time_ns

from app.settings import settings
from fastapi_limiter.depends import RateLimiter
from pyrate_limiter import BucketFactory, Limiter, Rate, RateItem
from pyrate_limiter.buckets.redis_bucket import RedisBucket
from redis.asyncio import ConnectionPool as AsyncConnectionPool
from redis.asyncio import Redis as AsyncRedis


pool = AsyncConnectionPool.from_url(settings.REDIS_ENDPOINT)
redis_db = AsyncRedis(connection_pool=pool)
from app.singletons.redis import RedisClient


class RedisBucketFactory(BucketFactory):
Expand All @@ -24,7 +19,7 @@ def wrap_item(self, name: str, weight: int = 1) -> RateItem:
async def get(self, item: RateItem) -> RedisBucket:
bucket_key = f"rate_limit:{item.name}"
if bucket_key not in self._buckets:
res = RedisBucket.init(self.rates, redis_db, bucket_key)
res = RedisBucket.init(self.rates, RedisClient.get(), bucket_key)
if inspect.isawaitable(res):
res = await res
self._buckets[bucket_key] = res
Expand Down
7 changes: 3 additions & 4 deletions src/backend/app/managers/websocket.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import asyncio
import contextlib
import logging
from contextlib import suppress

import redis.asyncio as redis
from fastapi import WebSocket, WebSocketDisconnect
from redis.asyncio.client import PubSub
from app.singletons.redis import RedisClient

from app.settings import settings
from app.singletons.redis import RedisClient
from app.states.app import AppState

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,7 +51,7 @@ async def stop(self) -> None:
"""Unsubscribe and cancel the background listener."""
if self._listener_task is not None:
self._listener_task.cancel()
with suppress(asyncio.CancelledError):
with contextlib.suppress(asyncio.CancelledError):
await self._listener_task
if self._pubsub is not None:
await self._pubsub.unsubscribe(settings.STATE_CHANNEL)
Expand Down
17 changes: 0 additions & 17 deletions src/backend/app/parser/time.py

This file was deleted.