Enable some more cacheing.

I'm not sure all of this is a good idea, and I'm not sure if all of it actually
works; in particular the fragment cacheing for toots.
This commit is contained in:
McBrayer 2019-01-30 10:56:13 -05:00
parent f1a7da0039
commit 6a6bf32646
2 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load humanize %} {% load humanize %}
{% load static %} {% load static %}
{% load cache %}
{% block title %} {% block title %}
Brutaldon ({{ own_acct.username }}) - {{ timeline_name }} timelime Brutaldon ({{ own_acct.username }}) - {{ timeline_name }} timelime
@ -23,11 +24,13 @@
<h1 class="title">Your {{ timeline_name }} timeline</h1> <h1 class="title">Your {{ timeline_name }} timeline</h1>
<div id="timeline"> <div id="timeline">
{% for toot in toots %} {% for toot in toots %}
{% cache 600 toot_partial toot.id %}
{% if toot.reblog %} {% if toot.reblog %}
{% include "main/toot_partial.html" with toot=toot.reblog reblog=True reblog_by=toot.account.acct reblog_icon=toot.account.avatar_static %} {% include "main/toot_partial.html" with toot=toot.reblog reblog=True reblog_by=toot.account.acct reblog_icon=toot.account.avatar_static %}
{% else %} {% else %}
{% include "main/toot_partial.html" with toot=toot reblog=False %} {% include "main/toot_partial.html" with toot=toot reblog=False %}
{% endif %} {% endif %}
{% endcache %}
<hr class="is-hidden"> <hr class="is-hidden">
{% endfor %} {% endfor %}

View File

@ -153,18 +153,22 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
'prev': prev, 'next': next}) 'prev': prev, 'next': next})
@br_login_required @br_login_required
@cache_page(60)
def home(request, next=None, prev=None): def home(request, next=None, prev=None):
return timeline(request, 'home', 'Home', max_id=next, since_id=prev) return timeline(request, 'home', 'Home', max_id=next, since_id=prev)
@br_login_required @br_login_required
@cache_page(60)
def local(request, next=None, prev=None): def local(request, next=None, prev=None):
return timeline(request, 'local', 'Local', max_id=next, since_id=prev) return timeline(request, 'local', 'Local', max_id=next, since_id=prev)
@br_login_required @br_login_required
@cache_page(60)
def fed(request, next=None, prev=None): def fed(request, next=None, prev=None):
return timeline(request, 'public', 'Federated', max_id=next, since_id=prev) return timeline(request, 'public', 'Federated', max_id=next, since_id=prev)
@br_login_required @br_login_required
@cache_page(60*5)
def tag(request, tag): def tag(request, tag):
try: try:
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
@ -343,6 +347,7 @@ def error(request):
return render(request, 'error.html', { 'error': _("Not logged in yet.")}) return render(request, 'error.html', { 'error': _("Not logged in yet.")})
@br_login_required @br_login_required
@cache_page(10)
def note(request, next=None, prev=None): def note(request, next=None, prev=None):
try: try:
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
@ -373,6 +378,7 @@ def note(request, next=None, prev=None):
'prev': prev, 'next': next}) 'prev': prev, 'next': next})
@br_login_required @br_login_required
@cache_page(60)
def thread(request, id): def thread(request, id):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
context = mastodon.status_context(id) context = mastodon.status_context(id)
@ -385,6 +391,7 @@ def thread(request, id):
'preferences': account.preferences}) 'preferences': account.preferences})
@br_login_required @br_login_required
@cache_page(60*5)
def user(request, username, prev=None, next=None): def user(request, username, prev=None, next=None):
try: try:
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
@ -847,6 +854,7 @@ def search(request):
}) })
@br_login_required @br_login_required
@cache_page(60*5)
def search_results(request): def search_results(request):
if request.method == 'GET': if request.method == 'GET':
query = request.GET.get('q', '') query = request.GET.get('q', '')
@ -863,6 +871,7 @@ def search_results(request):
'notifications': notifications, 'notifications': notifications,
"preferences": account.preferences}) "preferences": account.preferences})
@cache_page(60*30)
def about(request): def about(request):
version = django_settings.BRUTALDON_VERSION version = django_settings.BRUTALDON_VERSION
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
@ -875,6 +884,7 @@ def about(request):
"version": version, "version": version,
'own_acct': request.session.get('user', None), 'own_acct': request.session.get('user', None),
}) })
@cache_page(60*30)
def privacy(request): def privacy(request):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
if account: if account: