Skip to content

Fix the caching of featured projects #7054

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions readthedocs/rtd_tests/tests/test_views.py
Original file line number Diff line number Diff line change
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,22 @@ 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 TestHomepageCache(TestCase):

def setUp(self):
cache.clear()

def tearDown(self):
cache.clear()

def test_homepage_queries(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)
4 changes: 2 additions & 2 deletions readthedocs/templates/homepage.html
Original file line number Diff line number Diff line change
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