feat: Add cleanup mixin for outdated records

Introduces a CleanupMixin to periodically remove registrations in
the "started" state after 48 hours, finalized registrations
(denied/approved) older than 30 days, and expired IP blocks.
Enhances data management by ensuring stale entries are
automatically deleted.
This commit is contained in:
Kumi 2025-01-03 12:07:14 +01:00
parent a4a3c8d562
commit 8bdc6e4a45
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -30,7 +30,30 @@ class RateLimitMixin:
return super().dispatch(request, *args, **kwargs)
class LandingPageView(TemplateView):
class CleanupMixin:
def dispatch(self, request, *args, **kwargs):
# Remove all registrations that are still in the "started" state after 48 hours
UserRegistration.objects.filter(
status=UserRegistration.STATUS_STARTED,
timestamp__lt=timezone.now() - timedelta(hours=48),
).delete()
# Remove all registrations that are denied or approved after 30 days
UserRegistration.objects.filter(
status__in=[
UserRegistration.STATUS_DENIED,
UserRegistration.STATUS_APPROVED,
],
timestamp__lt=timezone.now() - timedelta(days=30),
).delete()
# Remove all IP blocks that have expired
IPBlock.objects.filter(expires__lt=timezone.now()).delete()
return super().dispatch(request, *args, **kwargs)
class LandingPageView(CleanupMixin, TemplateView):
template_name = "landing_page.html"