From 389e84183c1311800b2d261150180fa5dc44c910 Mon Sep 17 00:00:00 2001 From: extreme4all <> Date: Tue, 9 Jan 2024 20:32:47 +0100 Subject: [PATCH] minor changes --- src/api/v1/report.py | 16 +++++++++++++++- src/database/database.py | 7 ++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/v1/report.py b/src/api/v1/report.py index 4e44e7a..d1b8500 100644 --- a/src/api/v1/report.py +++ b/src/api/v1/report.py @@ -2,7 +2,7 @@ import time from datetime import date from typing import List, Optional - +import asyncio import pandas as pd from src.database import functions from src.database.functions import PLAYERDATA_ENGINE @@ -21,6 +21,7 @@ from sqlalchemy.orm import aliased from sqlalchemy.sql import func from sqlalchemy.sql.expression import Insert, Select, insert, select, update +from sqlalchemy import Text, text logger = logging.getLogger(__name__) router = APIRouter() @@ -198,6 +199,17 @@ async def update_reports( return {"detail": f"{data.rowcount} rows updated to reportingID = {new_user_id}."} +async def insert_active_reporter(reporter: str): + try: + sql: Text = text("INSERT INTO activeReporters (name) VALUES (:reporter)") + + async with PLAYERDATA_ENGINE.get_session() as session: + session: AsyncSession = session + async with session.begin(): + await session.execute(sql, {"reporter": reporter}) + except Exception as e: + logger.error(str(e)) + @router.post("/report", status_code=status.HTTP_201_CREATED, tags=["Report"]) async def insert_report( @@ -301,6 +313,8 @@ async def insert_report( logger.debug({"message": "No reporter in df_names", "detections": detections}) return + asyncio.create_task(insert_active_reporter(reporter[0])) + # if reporter_id[0] == 657248: # logger.debug({"message": "Temporary ignoring anonymous reporter"}) # return diff --git a/src/database/database.py b/src/database/database.py index f3f7efd..0f037f6 100644 --- a/src/database/database.py +++ b/src/database/database.py @@ -36,9 +36,10 @@ def __get_engine(self, connection_string) -> AsyncEngine: connection_string, poolclass=QueuePool, pool_pre_ping=True, - pool_size=100, - max_overflow=5000, - pool_recycle=3600, + pool_size=10, + max_overflow=90, + pool_timeout=30 + pool_recycle=60, ) return engine