Skip to content

Commit d5d753d

Browse files
authored
Merge pull request #6876 from readthedocs/cache-robotstxt
Add 12 hour caching to our robots.txt serving
2 parents 95a2eaf + d030d67 commit d5d753d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

readthedocs/proxito/tests/test_full.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import django_dynamic_fixture as fixture
77
from django.conf import settings
8+
from django.core.cache import cache
89
from django.http import HttpResponse
910
from django.test.utils import override_settings
1011
from django.urls import reverse
@@ -236,6 +237,11 @@ def test_project_nginx_serving_unicode_filename(self):
236237
class TestAdditionalDocViews(BaseDocServing):
237238
# Test that robots.txt and sitemap.xml work
238239

240+
def tearDown(self):
241+
super().tearDown()
242+
# Cleanup cache to avoid throttling on tests
243+
cache.clear()
244+
239245
@mock.patch('readthedocs.proxito.views.serve.get_storage_class')
240246
def test_default_robots_txt(self, storage_mock):
241247
storage_mock()().exists.return_value = False
@@ -326,7 +332,8 @@ def test_directory_indexes_get_args(self):
326332
self.project.versions.update(active=True, built=True)
327333
# Confirm we've serving from storage for the `index-exists/index.html` file
328334
response = self.client.get(
329-
reverse('proxito_404_handler', kwargs={'proxito_path': '/en/latest/index-exists?foo=bar'}),
335+
reverse('proxito_404_handler', kwargs={
336+
'proxito_path': '/en/latest/index-exists?foo=bar'}),
330337
HTTP_HOST='project.readthedocs.io',
331338
)
332339
self.assertEqual(

readthedocs/proxito/views/serve.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class ServeError404(SettingsOverrideObject):
309309
class ServeRobotsTXTBase(ServeDocsMixin, View):
310310

311311
@method_decorator(map_project_slug)
312+
@method_decorator(cache_page(60 * 60 * 12)) # 12 hours
312313
def get(self, request, project):
313314
"""
314315
Serve custom user's defined ``/robots.txt``.
@@ -369,7 +370,7 @@ class ServeRobotsTXT(SettingsOverrideObject):
369370
class ServeSitemapXMLBase(View):
370371

371372
@method_decorator(map_project_slug)
372-
@method_decorator(cache_page(60 * 60 * 24 * 3)) # 3 days
373+
@method_decorator(cache_page(60 * 60 * 12)) # 12 hours
373374
def get(self, request, project):
374375
"""
375376
Generate and serve a ``sitemap.xml`` for a particular ``project``.

0 commit comments

Comments
 (0)