Commit 79f5e039 authored by Chris Lamb's avatar Chris Lamb 💬

Cache the expensive landing page queries.

parent 1fb0d71a
from django.shortcuts import render
from django.core.cache import cache
from bidb.utils.lock import lock
from bidb.buildinfo.buildinfo_submissions.models import Submission
LANDING_CACHE_TIMEOUT = 60 * 10
def landing(request):
latest = Submission.objects.select_related('key').order_by('-created')[:20]
with lock('landing'):
latest = cache.get('latest:latest')
if latest is None:
latest = Submission.objects.select_related('key').order_by(
'-created'
)[:20]
cache.set('latest:latest', latest, LANDING_CACHE_TIMEOUT)
num_submissions = cache.get('latest:num_submissions')
if num_submissions is None:
num_submissions = Submission.objects.count()
cache.set(
'latest:num_submissions',
num_submissions,
LANDING_CACHE_TIMEOUT,
)
return render(
request,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment