core: delete expired models when filtering instead of excluding them

closes #3233

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-07-09 13:40:36 +02:00
parent 2432e51970
commit 9a9ba2560b
1 changed files with 3 additions and 2 deletions

View File

@ -482,8 +482,9 @@ class ExpiringModel(models.Model):
def filter_not_expired(cls, **kwargs) -> QuerySet: def filter_not_expired(cls, **kwargs) -> QuerySet:
"""Filer for tokens which are not expired yet or are not expiring, """Filer for tokens which are not expired yet or are not expiring,
and match filters in `kwargs`""" and match filters in `kwargs`"""
expired = Q(expires__lt=now(), expiring=True) for obj in cls.objects.filter(**kwargs).filter(Q(expires__lt=now(), expiring=True)):
return cls.objects.exclude(expired).filter(**kwargs) obj.delete()
return cls.objects.filter(**kwargs)
@property @property
def is_expired(self) -> bool: def is_expired(self) -> bool: