Skip to content

Commit

Permalink
Merge pull request #510 from Bot-detector/develop
Browse files Browse the repository at this point in the history
minor changes
  • Loading branch information
extreme4all authored Jan 9, 2024
2 parents e2e1545 + 389e841 commit 11ea943
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/api/v1/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 11ea943

Please sign in to comment.