Skip to content

Commit

Permalink
Add logging of removed rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Grennith committed Sep 23, 2023
1 parent c0687a8 commit 2a07e6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mapadroid/db/helper/PokemonHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion mapadroid/db/helper/PokestopIncidentHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2a07e6d

Please sign in to comment.