1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixed changelog purging frequency

This commit is contained in:
Jeremy Stretch
2018-06-22 16:23:07 -04:00
parent 3bdfe9c249
commit 36971b7651

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from datetime import timedelta from datetime import timedelta
import logging
import random import random
import uuid import uuid
@ -31,13 +30,11 @@ def record_object_change(user, request_id, instance, **kwargs):
instance.log_change(user, request_id, action) instance.log_change(user, request_id, action)
# 1% chance of clearing out expired ObjectChanges # 1% chance of clearing out expired ObjectChanges
if settings.CHANGELOG_RETENTION and random.randint(1, 100): if settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:
cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION) cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
purged_count, _ = ObjectChange.objects.filter( purged_count, _ = ObjectChange.objects.filter(
time__lt=cutoff time__lt=cutoff
).delete() ).delete()
logger = logging.getLogger('django')
logger.info("Automatically purged {} changes past the retention period".format(purged_count))
class ChangeLoggingMiddleware(object): class ChangeLoggingMiddleware(object):