Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor changes #510

Merged
merged 1 commit into from
Jan 9, 2024
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
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