Skip to content

Commit

Permalink
alru-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Jun 9, 2024
1 parent 10ae950 commit cf93e3e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ services:
condition: service_healthy

mysql:
container_name: database
container_name: rp-worker-db
build:
context: ./mysql
image: bot-detector/mysql:latest
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ SQLAlchemy==2.0.30
tomli==2.0.1
typing_extensions==4.12.0
virtualenv==20.26.2
async_lru==2.0.4
2 changes: 2 additions & 0 deletions src/app/controllers/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sqlalchemy as sqla
from app.controllers.db_handler import DatabaseHandler
from app.views.player import PlayerCreate, PlayerInDB
from async_lru import alru_cache
from database.database import model_to_dict
from database.models.player import Player as DBPlayer
from sqlalchemy.ext.asyncio import AsyncSession
Expand All @@ -13,6 +14,7 @@ def __init__(self, session: AsyncSession):
def sanitize_name(self, player_name: str) -> str:
return player_name.lower().replace("_", " ").replace("-", " ").strip()

@alru_cache(maxsize=2048)
async def get(self, player_name: str) -> PlayerInDB:
player_name = self.sanitize_name(player_name)
sql = sqla.select(DBPlayer).where(DBPlayer.name == player_name)
Expand Down
2 changes: 2 additions & 0 deletions src/app/controllers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
StgReportCreate,
StgReportInDB,
)
from async_lru import alru_cache
from database.database import model_to_dict
from database.models.report import Report as DBReport
from database.models.report import StgReport as DBSTGReport
Expand All @@ -14,6 +15,7 @@ class ReportController(DatabaseHandler):
def __init__(self, session: AsyncSession):
self.session = session

@alru_cache(maxsize=2048)
async def get(
self, reported_id: int, reporting_id: int, region_id: int
) -> StgReportInDB:
Expand Down

0 comments on commit cf93e3e

Please sign in to comment.