mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-24 20:39:59 -06:00
Closes #6590: Introduce a nightly housekeeping command to clear expired sessions and change records
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
from cacheops.signals import cache_invalidated, cache_read
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import DEFAULT_DB_ALIAS
|
||||
from django.db.models.signals import m2m_changed, post_save, pre_delete
|
||||
from django.dispatch import receiver
|
||||
from django.utils import timezone
|
||||
from django_prometheus.models import model_deletes, model_inserts, model_updates
|
||||
from prometheus_client import Counter
|
||||
|
||||
@@ -79,11 +74,6 @@ def _handle_changed_object(request, webhook_queue, 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)._raw_delete(using=DEFAULT_DB_ALIAS)
|
||||
|
||||
|
||||
def _handle_deleted_object(request, webhook_queue, sender, instance, **kwargs):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user