-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Not sure why yet but in multiple places redirect is called from within the views.py, some of these redirects are to provide backward compatibility for deprecated urls others seem to be redirecting to the next step in processing a search request.
It would be better for the server and resources if we weren't doing any of these redirects. It would also allow us to rate limit for malicious bot use.
It might be worth the less than satisfactory solution of blocking the process for 1 or 2 seconds on redirect:
diff --git a/grantnav/frontend/views.py b/grantnav/frontend/views.py
index dbfe054..e5569a7 100644
--- a/grantnav/frontend/views.py
+++ b/grantnav/frontend/views.py
@@ -5,6 +5,7 @@ import datetime
import json
import re
import urllib
+import time
from itertools import chain
import dateutil.parser as date_parser
from dateutil.relativedelta import relativedelta
@@ -12,7 +13,8 @@ from dateutil.relativedelta import relativedelta
from django.http import Http404, JsonResponse
from django.http import HttpResponse, StreamingHttpResponse
from django.views.decorators.clickjacking import xframe_options_exempt
-from django.shortcuts import render, redirect
+from django.shortcuts import render
+from django.shortcuts import redirect as django_redirect
from django.utils.http import urlencode
from django.urls import reverse
from django.core.cache import cache
@@ -133,6 +135,9 @@ SEARCH_SUMMARY_AGGREGATES = {
"latest_grant": {"top_hits": {"size": 1, "sort": [{"awardDate": {"order": "desc"}}]}},
}
+def redirect(to, *args, **kwargs):
+ time.sleep(1)
+ return django_redirect(to, *args, **kwargs)
def grants_csv_generator(query, grant_csv_titles, grant_csv_paths):
yield grant_csv_titles
Metadata
Metadata
Assignees
Labels
No labels