Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the caching of featured projects #7054

Merged
merged 4 commits into from May 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions readthedocs/rtd_tests/tests/test_views.py
Expand Up @@ -7,6 +7,7 @@
from django.urls import reverse
from django.utils import timezone
from django_dynamic_fixture import get, new
from django.core.cache import cache

from readthedocs.builds.constants import EXTERNAL, LATEST
from readthedocs.builds.models import Build, Version
Expand Down Expand Up @@ -359,3 +360,36 @@ def test_generated_csv_data(self):
self.assertEqual(len(body), 23)
self.assertEqual(body[0][1], 'advertising')
self.assertEqual(body[-1][1], 'hello world')


class TestHomepage(TestCase):

def setUp(self):
self.eric = User(username='eric')
self.eric.set_password('test')
self.eric.save()

def tearDown(self):
cache.clear()

def test_homepage_queries_logged_out(self):
with self.assertNumQueries(1):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)

# Cache
with self.assertNumQueries(0):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)

def test_homepage_queries_logged_in(self):
self.client.login(username='eric', password='test')

with self.assertNumQueries(9):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)

# Cache
with self.assertNumQueries(8):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)
4 changes: 2 additions & 2 deletions readthedocs/templates/homepage.html
Expand Up @@ -114,9 +114,9 @@ <h3>Multiple versions</h3>
{% include "core/widesearchbar.html" %}
</section>

{% if featured_list %}
{% get_current_language as language %}
{% cache 600 homepage_featured_list language %}
{% if featured_list %}
<!-- BEGIN projects list -->
<section>
<h3>{% trans "Featured Projects" %}</h3>
Expand All @@ -129,8 +129,8 @@ <h3>{% trans "Featured Projects" %}</h3>
</div>
</section>
<!-- END projects list -->
{% endcache %}
{% endif %}
{% endcache %}

<!-- Funding and Contributing -->
<section>
Expand Down