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

Cleanup from earlier work on caching

This commit is contained in:
Jeremy Stretch
2019-04-22 14:49:31 -04:00
parent 1be5cf8184
commit c2d0e8fd95
10 changed files with 1 additions and 30 deletions

View File

@ -6,7 +6,6 @@ from django.db import transaction
from django.db.models import Count from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from extras.models import Graph, GRAPH_TYPE_PROVIDER from extras.models import Graph, GRAPH_TYPE_PROVIDER
@ -35,7 +34,6 @@ class ProviderListView(PermissionRequiredMixin, ObjectListView):
class ProviderView(PermissionRequiredMixin, View): class ProviderView(PermissionRequiredMixin, View):
permission_required = 'circuits.view_provider' permission_required = 'circuits.view_provider'
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def get(self, request, slug): def get(self, request, slug):
provider = get_object_or_404(Provider, slug=slug) provider = get_object_or_404(Provider, slug=slug)
@ -151,7 +149,6 @@ class CircuitListView(PermissionRequiredMixin, ObjectListView):
class CircuitView(PermissionRequiredMixin, View): class CircuitView(PermissionRequiredMixin, View):
permission_required = 'circuits.view_circuit' permission_required = 'circuits.view_circuit'
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def get(self, request, pk): def get(self, request, pk):
circuit = get_object_or_404(Circuit.objects.select_related('provider', 'type', 'tenant__group'), pk=pk) circuit = get_object_or_404(Circuit.objects.select_related('provider', 'type', 'tenant__group'), pk=pk)

View File

@ -7,8 +7,6 @@ from django.db.models import Count, Q
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from django_tables2 import RequestConfig from django_tables2 import RequestConfig

View File

@ -3,8 +3,6 @@ from django.conf import settings
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Count, Q from django.db.models import Count, Q
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from django_tables2 import RequestConfig from django_tables2 import RequestConfig

View File

@ -45,8 +45,6 @@ BASE_PATH = getattr(configuration, 'BASE_PATH', '')
if BASE_PATH: if BASE_PATH:
BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only
CACHE_TIMEOUT = getattr(configuration, 'CACHE_TIMEOUT', 900) CACHE_TIMEOUT = getattr(configuration, 'CACHE_TIMEOUT', 900)
CACHE_MAX_ENTRIES = getattr(configuration, 'CACHE_MAX_ENTRIES', 300)
CACHE_CULL_FREQUENCY = getattr(configuration, 'CACHE_CULL_FREQUENCY', 3)
CHANGELOG_RETENTION = getattr(configuration, 'CHANGELOG_RETENTION', 90) CHANGELOG_RETENTION = getattr(configuration, 'CHANGELOG_RETENTION', 90)
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False) CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', []) CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])

View File

@ -1,10 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from django.conf import settings
from django.db.models import Count, F from django.db.models import Count, F
from django.shortcuts import render from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse

View File

@ -1,14 +1,11 @@
import base64 import base64
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import permission_required, login_required from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Count from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from dcim.models import Device from dcim.models import Device

View File

@ -1,9 +1,6 @@
from django.conf import settings
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Count from django.db.models import Count
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from circuits.models import Circuit from circuits.models import Circuit

View File

@ -6,8 +6,6 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError, MultipleObjectsReturned, ObjectDoesNotExist from django.core.exceptions import FieldError, MultipleObjectsReturned, ObjectDoesNotExist
from django.db.models import ManyToManyField from django.db.models import ManyToManyField
from django.http import Http404 from django.http import Http404
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from rest_framework.permissions import BasePermission from rest_framework.permissions import BasePermission
from rest_framework.relations import PrimaryKeyRelatedField, RelatedField from rest_framework.relations import PrimaryKeyRelatedField, RelatedField
@ -276,14 +274,12 @@ class ModelViewSet(_ModelViewSet):
# Fall back to the hard-coded serializer class # Fall back to the hard-coded serializer class
return self.serializer_class return self.serializer_class
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def list(self, *args, **kwargs): def list(self, *args, **kwargs):
""" """
Call to super to allow for caching Call to super to allow for caching
""" """
return super().list(*args, **kwargs) return super().list(*args, **kwargs)
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def retrieve(self, *args, **kwargs): def retrieve(self, *args, **kwargs):
""" """
Call to super to allow for caching Call to super to allow for caching
@ -326,11 +322,9 @@ class FieldChoicesViewSet(ViewSet):
}) })
self._fields[key] = choices self._fields[key] = choices
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def list(self, request): def list(self, request):
return Response(self._fields) return Response(self._fields)
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
def retrieve(self, request, pk): def retrieve(self, request, pk):
if pk not in self._fields: if pk not in self._fields:
raise Http404 raise Http404

View File

@ -17,8 +17,6 @@ from django.urls import reverse
from django.utils.html import escape from django.utils.html import escape
from django.utils.http import is_safe_url from django.utils.http import is_safe_url
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import requires_csrf_token from django.views.decorators.csrf import requires_csrf_token
from django.views.defaults import ERROR_500_TEMPLATE_NAME from django.views.defaults import ERROR_500_TEMPLATE_NAME
from django.views.generic import View from django.views.generic import View

View File

@ -1,12 +1,9 @@
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction from django.db import transaction
from django.db.models import Count from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import View from django.views.generic import View
from dcim.models import Device, Interface from dcim.models import Device, Interface