Skip to content

Commit

Permalink
Run optimize on every 10th run
Browse files Browse the repository at this point in the history
  • Loading branch information
Grennith committed Oct 8, 2023
1 parent 1a55a6d commit 831384a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mapadroid/db/DbCleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def stop(self):
self.__cleanup_task = None

async def _run_cleanup_routine(self):
optimize_counter: int = 0
while True:
try:
async with self.__db_wrapper as session, session:
Expand All @@ -43,16 +44,21 @@ async def _run_cleanup_routine(self):
await PokemonHelper.delete_older_than_n_hours(session,
MadGlobals.application_args.delete_mons_n_hours,
mon_limit)
await PokemonHelper.run_optimize(session)
if optimize_counter == 0:
logger.info("Cleanup reached threshold to call optimize for pokemon table")
await PokemonHelper.run_optimize(session)
if MadGlobals.application_args.delete_incidents_n_hours:
logger.info("Cleaning up records of incidents disappeared more than {} hours ago.",
MadGlobals.application_args.delete_incidents_n_hours)
await PokestopIncidentHelper.delete_older_than_n_hours(
session, MadGlobals.application_args.delete_incidents_n_hours, mon_limit)
await PokestopIncidentHelper.run_optimize(session)
if optimize_counter == 0:
logger.info("Cleanup reached threshold to call optimize for incident table")
await PokestopIncidentHelper.run_optimize(session)
await session.commit()
logger.success("Done cleaning up DB, sleeping {}s", MadGlobals.application_args.cleanup_interval)
except Exception as e:
logger.error("Failed cleaning up DB.")
logger.exception(e)
await asyncio.sleep(MadGlobals.application_args.cleanup_interval)
optimize_counter = (optimize_counter + 1) % 10

0 comments on commit 831384a

Please sign in to comment.