Skip to content

Commit

Permalink
cache the button popups for a long time (bug 562231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbalogh committed Apr 28, 2010
1 parent 1be791d commit 878beae
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apps/addons/buttons.py
@@ -1,4 +1,5 @@
from django.db.models import Q
from django.views.decorators.cache import cache_page

import jingo
import jinja2
Expand Down Expand Up @@ -199,6 +200,8 @@ def __init__(self, text, url, os=None, file=None):
self.text, self.url, self.os, self.file = text, url, os, file


# Cache it for a year.
@cache_page(60 * 60 * 24 * 365)
def js(request):
return jingo.render(request, 'addons/popups.html',
content_type='text/javascript')
Expand Down
16 changes: 14 additions & 2 deletions apps/addons/tests/test_views.py
@@ -1,3 +1,6 @@
from datetime import datetime

from django import test
from django.conf import settings
from django.core.cache import cache

Expand Down Expand Up @@ -172,8 +175,8 @@ def test_compatible_app_redirect(self):
"""
addon = Addon.objects.get(id=3615)
comp_app = addon.compatible_apps.keys()[0]
not_comp_app = [ a for a in amo.APP_USAGE if a not in
addon.compatible_apps.keys() ][0]
not_comp_app = [a for a in amo.APP_USAGE
if a not in addon.compatible_apps.keys()][0]

# no SeaMonkey version => redirect
prefixer = amo.urlresolvers.get_url_prefix()
Expand Down Expand Up @@ -282,6 +285,7 @@ def test__details_collections_dropdown(self):
ret = _details_collections_dropdown(request, profile, addon)
eq_(len(ret), 1)


class TestTagsBox(test_utils.TestCase):
fixtures = ['base/addontag']

Expand All @@ -290,3 +294,11 @@ def test_tag_box(self):
r = self.client.get(reverse('addons.detail', args=[8680]), follow=True)
doc = pq(r.content)
eq_('SEO', doc('#tags ul').children().text())


def test_button_caching():
"""The button popups should be cached for a long time."""
response = test.Client().get(reverse('addons.buttons.js'), follow=True)
fmt = '%a, %d %b %Y %H:%M:%S GMT'
expires = datetime.strptime(response['Expires'], fmt)
assert (expires - datetime.now()).days >= 365
8 changes: 7 additions & 1 deletion apps/minify/helpers.py
@@ -1,14 +1,15 @@
from django.conf import settings

from jingo import register
from jinja2 import Markup
from jingo import register, env


try:
from build import BUILD_ID_CSS, BUILD_ID_JS
except ImportError:
BUILD_ID_CSS = BUILD_ID_JS = 'dev'


def _build_html(items, wrapping):
"""
Wrap `items` in wrapping.
Expand Down Expand Up @@ -44,3 +45,8 @@ def css(bundle, media="screen,projection,tv", debug=settings.TEMPLATE_DEBUG):

return _build_html(items,
"""<link rel="stylesheet" media="%s" href="%%s" />""" % media)


def build_ids(request):
"""A context processor for injecting the css/js build ids."""
return {'BUILD_ID_CSS': BUILD_ID_CSS, 'BUILD_ID_JS': BUILD_ID_JS}
5 changes: 3 additions & 2 deletions settings.py
Expand Up @@ -135,12 +135,14 @@
'amo.context_processors.app',
'amo.context_processors.i18n',
'amo.context_processors.global_settings',
'minify.helpers.build_ids',
)

TEMPLATE_DIRS = (
path('templates'),
)


def JINJA_CONFIG():
import jinja2
from django.conf import settings
Expand All @@ -160,7 +162,6 @@ def JINJA_CONFIG():
return config



MIDDLEWARE_CLASSES = (
'commonware.log.ThreadRequestMiddleware',
# AMO URL middleware comes first so everyone else sees nice URLs.
Expand Down Expand Up @@ -284,7 +285,7 @@ def JINJA_CONFIG():
),
'zamboni/discovery-pane': (
'css/zamboni/discovery-pane.css',
)
),
},
'js': {
# JS files common to the entire site.
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Expand Up @@ -71,7 +71,7 @@
{# js #}
<script src="{{ url('django.views.i18n.javascript_catalog') }}"></script>
{{ js('common') }}
<script async defer src="{{ url('addons.buttons.js') }}"></script>
<script async defer src="{{ url('addons.buttons.js') }}?build={{ BUILD_ID_JS }}"></script>
{% block js %}{% endblock %}
{% include "footer.html" %}
{# Webtrends Stats Tracking #}
Expand Down

0 comments on commit 878beae

Please sign in to comment.