Browse Source

Add the `prunetokenbucket` management command.

pull/230/head
Pēteris Caune 6 years ago
parent
commit
6040759601
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 32 additions and 2 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +10
    -2
      README.md
  3. +17
    -0
      hc/api/management/commands/prunetokenbucket.py

+ 5
- 0
CHANGELOG.md View File

@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.
## Unreleased
### Improvements
- Add the `prunetokenbucket` management command
## 1.7.0 - 2019-05-02
### Improvements


+ 10
- 2
README.md View File

@ -258,9 +258,9 @@ There are separate Django management commands for each task:
```
* Remove user accounts that match either of these conditions:
* Account was created more than 6 months ago, and user has never logged in.
* Account was created more than 6 months ago, and user has never logged in.
These can happen when user enters invalid email address when signing up.
* Last login was more than 6 months ago, and the account has no checks.
* Last login was more than 6 months ago, and the account has no checks.
Assume the user doesn't intend to use the account any more and would
probably *want* it removed.
@ -268,6 +268,14 @@ There are separate Django management commands for each task:
$ ./manage.py pruneusers
```
* Remove old records fromt he `api_tokenbucket` table. The TokenBucket
model is used for rate-limiting login attempts and similar operations.
Any records older than one day can be safely removed.
```
$ ./manage.py prunetokenbucket
```
When you first try these commands on your data, it is a good idea to
test them on a copy of your database, not on the live database right away.
In a production setup, you should also have regular, automated database


+ 17
- 0
hc/api/management/commands/prunetokenbucket.py View File

@ -0,0 +1,17 @@
from datetime import timedelta
from django.core.management.base import BaseCommand
from django.utils.timezone import now
from hc.api.models import TokenBucket
class Command(BaseCommand):
help = 'Prune pings based on limits in user profiles'
def handle(self, *args, **options):
day_ago = now() - timedelta(days=1)
q = TokenBucket.objects.filter(updated__lt=day_ago)
n_pruned, _ = q.delete()
return "Done! Pruned %d token bucket entries" % n_pruned

Loading…
Cancel
Save