forked from GithubBackups/healthchecks
"prunenotifications" management command
This commit is contained in:
parent
c6d5e64286
commit
0b6d484bd5
@ -190,6 +190,13 @@ There are separate Django management commands for each task:
|
|||||||
$ ./manage.py pruneemails
|
$ ./manage.py pruneemails
|
||||||
````
|
````
|
||||||
|
|
||||||
|
* Remove old records of sent notifications. For each check, remove
|
||||||
|
notifications that are older than the oldest stored ping for same check.
|
||||||
|
|
||||||
|
````
|
||||||
|
$ ./manage.py prunenotifications
|
||||||
|
````
|
||||||
|
|
||||||
* Remove user accounts that match either of these conditions:
|
* Remove user accounts that match either of these conditions:
|
||||||
* Account was created more than a month ago, and user has never logged in.
|
* Account was created more than a month ago, and user has never logged in.
|
||||||
These can happen when user enters invalid email address when signing up.
|
These can happen when user enters invalid email address when signing up.
|
||||||
|
22
hc/api/management/commands/prunenotifications.py
Normal file
22
hc/api/management/commands/prunenotifications.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.db.models import Min
|
||||||
|
|
||||||
|
from hc.api.models import Notification, Check
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Prune stored notifications'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
q = Check.objects.filter(n_pings__gt=0)
|
||||||
|
q = q.annotate(min_ping_date=Min("ping__created"))
|
||||||
|
for check in q:
|
||||||
|
qq = Notification.objects.filter(owner_id=check.id,
|
||||||
|
created__lt=check.min_ping_date)
|
||||||
|
|
||||||
|
num_deleted, _ = qq.delete()
|
||||||
|
total += num_deleted
|
||||||
|
|
||||||
|
return "Done! Pruned %d notifications." % total
|
Loading…
x
Reference in New Issue
Block a user