Răsfoiți Sursa

restores config revision during cache clear #14182

Abhimanyu Saharan 2 ani în urmă
părinte
comite
e1bedb8350
1 a modificat fișierele cu 9 adăugiri și 0 ștergeri
  1. 9 0
      netbox/core/management/commands/clearcache.py

+ 9 - 0
netbox/core/management/commands/clearcache.py

@@ -1,11 +1,20 @@
 from django.core.cache import cache
 from django.core.cache import cache
 from django.core.management.base import BaseCommand
 from django.core.management.base import BaseCommand
 
 
+from extras.models import ConfigRevision
+
 
 
 class Command(BaseCommand):
 class Command(BaseCommand):
     """Command to clear the entire cache."""
     """Command to clear the entire cache."""
     help = 'Clears the cache.'
     help = 'Clears the cache.'
 
 
     def handle(self, *args, **kwargs):
     def handle(self, *args, **kwargs):
+        # Fetch the current config revision from the cache
+        config_version = cache.get('config_version')
+        # Clear the cache
         cache.clear()
         cache.clear()
         self.stdout.write('Cache has been cleared.', ending="\n")
         self.stdout.write('Cache has been cleared.', ending="\n")
+        if config_version:
+            # Activate the current config revision
+            ConfigRevision.objects.get(id=config_version).activate()
+            self.stdout.write(f'Config revision ({config_version}) has been restored.', ending="\n")