mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Move housekeeping to _handle_changed_object()
This commit is contained in:
@ -48,12 +48,3 @@ class ObjectChangeMiddleware(object):
|
||||
pre_delete.disconnect(handle_deleted_object, dispatch_uid='handle_deleted_object')
|
||||
|
||||
return response
|
||||
|
||||
# TODO: Put this somewhere
|
||||
# # Housekeeping: 1% chance of clearing out expired ObjectChanges. This applies only to requests which result in
|
||||
# # one or more changes being logged.
|
||||
# if settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:
|
||||
# cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
|
||||
# purged_count, _ = ObjectChange.objects.filter(
|
||||
# time__lt=cutoff
|
||||
# ).delete()
|
||||
|
@ -1,8 +1,14 @@
|
||||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
from cacheops.signals import cache_invalidated, cache_read
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django_prometheus.models import model_deletes, model_inserts, model_updates
|
||||
from prometheus_client import Counter
|
||||
|
||||
from .choices import ObjectChangeActionChoices
|
||||
from .models import ObjectChange
|
||||
from .webhooks import enqueue_webhooks
|
||||
|
||||
|
||||
@ -41,6 +47,11 @@ def _handle_changed_object(request, sender, instance, **kwargs):
|
||||
elif action == ObjectChangeActionChoices.ACTION_UPDATE:
|
||||
model_updates.labels(instance._meta.model_name).inc()
|
||||
|
||||
# Housekeeping: 0.1% chance of clearing out expired ObjectChanges
|
||||
if settings.CHANGELOG_RETENTION and random.randint(1, 1000) == 1:
|
||||
cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
|
||||
ObjectChange.objects.filter(time__lt=cutoff).delete()
|
||||
|
||||
|
||||
def _handle_deleted_object(request, sender, instance, **kwargs):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user