From f82b3175a9e5a03cf5a029b909032763db86f786 Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 23 Oct 2026 02:33:31 +0200 Subject: [PATCH] delete expired verifications in a single query Co-Authored-By: Claude Opus 5.5 --- bot/src/cogs/galtinn.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/bot/src/cogs/galtinn.py b/bot/src/cogs/galtinn.py index b643768..98158db 100644 --- a/bot/src/cogs/galtinn.py +++ b/bot/src/cogs/galtinn.py @@ -1,8 +1,6 @@ import asyncio import secrets import urllib.parse -from datetime import datetime -from datetime import timezone import aiohttp import discord @@ -489,22 +487,12 @@ class Galtinn(commands.Cog): Clean up any pending verifications that have expired. This is in case the register command fails to do so """ - results = await self.bot.db.fetch( + await self.bot.db.execute( """ - SELECT discord_id, expires - FROM galtinn_verification; + DELETE FROM galtinn_verification + WHERE expires < NOW() AT TIME ZONE 'utc'; """ ) - for result in results: - discord_id, expires = list(result) - if expires < datetime.now(timezone.utc).replace(tzinfo=None): - await self.bot.db.execute( - """ - DELETE FROM galtinn_verification - WHERE discord_id = $1; - """, - discord_id, - ) @verification_cleanup.before_loop async def before_verification_cleanup(self):