Skip to content

Commit

Permalink
Remove cache_page decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ronardcaktus committed Oct 24, 2024
1 parent a6fe60d commit e2dc8f8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
14 changes: 0 additions & 14 deletions nc/views/arrests.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import django_filters
import pandas as pd

from django.conf import settings
from django.db.models import Count, Q, Sum
from django.db.models.functions import ExtractYear
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.response import Response
from rest_framework.views import APIView

from nc.constants import CONTRABAND_TYPE_COLS, DEFAULT_RENAME_COLUMNS, STATEWIDE
from nc.models import ContrabandSummary, StopPurpose, StopPurposeGroup, StopSummary

CACHE_TIMEOUT = settings.CACHE_COUNT_TIMEOUT


def create_table_data_response(qs, pivot_columns=None, value_key=None, rename_columns=None):
rename_cols = rename_columns if rename_columns else DEFAULT_RENAME_COLUMNS
Expand Down Expand Up @@ -196,7 +191,6 @@ def sort_by_stop_purpose_group(df):
class AgencyArrestsPercentageOfStopsView(APIView):
"""Traffic Stops Leading to Arrest by Percentage"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Build chart data
chart_df = arrest_query(request, agency_id, group_by=("driver_race_comb",))
Expand All @@ -211,7 +205,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfSearchesView(APIView):
"""Searches Leading to Arrest by Percentage"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Build chart data
chart_df = arrest_query(request, agency_id, group_by=("driver_race_comb",))
Expand All @@ -226,7 +219,6 @@ def get(self, request, agency_id):
class AgencyCountOfStopsAndArrests(APIView):
"""Traffic Stops Leading to Arrest by Count"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Build chart data
chart_df = arrest_query(request, agency_id, group_by=("driver_race_comb",)).sort_values(
Expand All @@ -245,7 +237,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfStopsByGroupPurposeView(APIView):
"""Percentage of Stops Leading to Arrest by Stop Purpose Group"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Conditionally build table data
if request.query_params.get("modal"):
Expand All @@ -269,7 +260,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfStopsPerStopPurposeView(APIView):
"""Percentage of Stops Leading to Arrest by Stop Purpose Type"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Conditionally build table data
if request.query_params.get("modal"):
Expand All @@ -292,7 +282,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfSearchesByGroupPurposeView(APIView):
"""Percentage of Searches Leading to Arrest by Stop Purpose Group"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Conditionally build table data
if request.query_params.get("modal"):
Expand All @@ -313,7 +302,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfSearchesPerStopPurposeView(APIView):
"""Percentage of Searches Leading to Arrest by Stop Purpose Type"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
# Conditionally build table data
if request.query_params.get("modal"):
Expand All @@ -339,7 +327,6 @@ def get(self, request, agency_id):
class AgencyArrestsPercentageOfStopsPerContrabandTypeView(APIView):
"""Percentage of Stops Leading to Arrest by Discovered Contraband Type"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
chart_df = contraband_query(request, agency_id, group_by=("contraband_type",))
chart_data = chart_df["driver_contraband_arrest_rate"].to_list()
Expand All @@ -358,7 +345,6 @@ def get(self, request, agency_id):
class AgencyStopsYearRange(APIView):
"""Returns list of years with data for agency/officer"""

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
filter_set = ArrestSummaryFilterSet(request.GET, agency_id=agency_id)
year_range = filter_set.qs.order_by("-year").values_list("year", flat=True).distinct("year")
Expand Down
18 changes: 1 addition & 17 deletions nc/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.db.models import Count, Q, Sum
from django.db.models.functions import ExtractYear
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.cache import never_cache
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from rest_framework.decorators import action
Expand Down Expand Up @@ -89,9 +89,6 @@ class QueryKeyConstructor(DefaultObjectKeyConstructor):
query_cache_key_func = QueryKeyConstructor()


CACHE_TIMEOUT = settings.CACHE_COUNT_TIMEOUT


def get_date_range(request):
# Only filter is from and to values are found and are valid
date_precision = "year"
Expand Down Expand Up @@ -375,7 +372,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
stop_qs = StopSummary.objects.all().annotate(year=ExtractYear("date"))

Expand Down Expand Up @@ -473,7 +469,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
date_precision, date_range = get_date_range(request)

Expand Down Expand Up @@ -519,7 +514,6 @@ def get_values(self, df, stop_purpose, years_len):
else:
return [0] * years_len

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
date_precision, date_range = get_date_range(request)
qs = StopSummary.objects.all()
Expand Down Expand Up @@ -629,7 +623,6 @@ def get_values(col):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
date_precision, date_range = get_date_range(request)
qs = StopSummary.objects.all()
Expand Down Expand Up @@ -707,7 +700,6 @@ def get(self, request, agency_id):


class AgencyContrabandView(APIView):
@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
year = request.GET.get("year", None)

Expand Down Expand Up @@ -770,7 +762,6 @@ def get(self, request, agency_id):


class AgencyContrabandTypesView(APIView):
@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
year = request.GET.get("year", None)

Expand Down Expand Up @@ -880,7 +871,6 @@ def get_values(col):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
year = request.GET.get("year", None)

Expand Down Expand Up @@ -1032,7 +1022,6 @@ def create_dataset(self, contraband_df, searches_df, stop_purpose):
data.append(group)
return data

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
year = request.GET.get("year", None)

Expand Down Expand Up @@ -1101,7 +1090,6 @@ def get(self, request, agency_id):


class AgencyContrabandStopGroupByPurposeModalView(APIView):
@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
grouped_stop_purpose = request.GET.get("grouped_stop_purpose")
contraband_type = request.GET.get("contraband_type")
Expand Down Expand Up @@ -1189,7 +1177,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
stop_qs = StopSummary.objects.all().annotate(year=ExtractYear("date"))

Expand Down Expand Up @@ -1302,7 +1289,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
date_precision, date_range = get_date_range(request)

Expand Down Expand Up @@ -1390,7 +1376,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
stop_qs = StopSummary.objects.all().annotate(year=ExtractYear("date"))
search_qs = StopSummary.objects.filter(search_type__isnull=False).annotate(
Expand Down Expand Up @@ -1518,7 +1503,6 @@ def get_values(race):
],
}

@method_decorator(cache_page(CACHE_TIMEOUT))
def get(self, request, agency_id):
qs = StopSummary.objects.filter(search_type__isnull=False, engage_force="t").annotate(
year=ExtractYear("date")
Expand Down

0 comments on commit e2dc8f8

Please sign in to comment.