From 2a07e6daf44aa0ca00d5460518adeb192b5cfaaf Mon Sep 17 00:00:00 2001 From: Till Skrodzki Date: Sat, 23 Sep 2023 09:08:55 +0300 Subject: [PATCH] Add logging of removed rows --- mapadroid/db/helper/PokemonHelper.py | 6 ++++-- mapadroid/db/helper/PokestopIncidentHelper.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mapadroid/db/helper/PokemonHelper.py b/mapadroid/db/helper/PokemonHelper.py index 5c49735fc..d506af802 100644 --- a/mapadroid/db/helper/PokemonHelper.py +++ b/mapadroid/db/helper/PokemonHelper.py @@ -3,7 +3,7 @@ from functools import reduce from typing import Dict, List, Optional, Set, Tuple -from sqlalchemy import and_, delete, desc, func, text +from sqlalchemy import Result, and_, delete, desc, func, text from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.future import select @@ -324,11 +324,13 @@ async def delete_older_than_n_hours(session: AsyncSession, hours: int, limit: Op # Rather ugly construct as stmt.with_dialect_options currently does not work # See https://groups.google.com/g/sqlalchemy/c/WDKhyAt6eAk/m/feteFNZnAAAJ stmt = text(f"{str(stmt)} LIMIT :limit") - await session.execute(stmt, + result = await session.execute(stmt, { "disappear_time_1": DatetimeWrapper.now() - datetime.timedelta(hours=hours), "limit": limit }) + # The resulting object is of type CursorResult -> rowcount is available + logger.info("Removed {} rows of mons", result.rowcount) else: await session.execute(stmt) diff --git a/mapadroid/db/helper/PokestopIncidentHelper.py b/mapadroid/db/helper/PokestopIncidentHelper.py index 46b173fff..3f64ff3bb 100644 --- a/mapadroid/db/helper/PokestopIncidentHelper.py +++ b/mapadroid/db/helper/PokestopIncidentHelper.py @@ -28,12 +28,14 @@ async def delete_older_than_n_hours(session: AsyncSession, hours: int, limit: Op # Rather ugly construct as stmt.with_dialect_options currently does not work # See https://groups.google.com/g/sqlalchemy/c/WDKhyAt6eAk/m/feteFNZnAAAJ stmt = text(f"{str(stmt)} LIMIT :limit") - await session.execute(stmt, + result = await session.execute(stmt, { "incident_expiration_1": DatetimeWrapper.now() - datetime.timedelta(hours=hours), "limit": limit } ) + # The resulting object is of type CursorResult -> rowcount is available + logger.info("Removed {} rows of incidents", result.rowcount) else: await session.execute(stmt)