Skip to content

Commit b08b68a

Browse files
Cache the historical comparison JSON for 30 minutes
1 parent 9a17e46 commit b08b68a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎codespeed/views.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
HttpResponseNotFound, StreamingHttpResponse
1515
from django.db.models import F
1616
from django.shortcuts import get_object_or_404, render
17+
from django.views.decorators.cache import cache_page
1718
from django.views.decorators.http import require_GET, require_POST
1819
from django.views.decorators.csrf import csrf_exempt
1920
from django.views.decorators.clickjacking import xframe_options_exempt
@@ -112,7 +113,15 @@ def embed_comparison(request):
112113
return render(request, 'embed_comparison.html', context)
113114

114115

116+
# The historical comparison only changes when new results are saved, which
117+
# happens at most a few times a day, yet computing it costs ~2s of database
118+
# time per request. Cache the rendered JSON server-side and let browsers
119+
# reuse it too.
120+
HISTORICAL_CACHE_SECONDS = 30 * 60
121+
122+
115123
@require_GET
124+
@cache_page(HISTORICAL_CACHE_SECONDS)
116125
def gethistoricaldata(request):
117126
# 'labels' maps each key in tagged_revs (plus baseline and 'latest') to
118127
# a two-line label [tag, project] for the x axis of the history chart.

0 commit comments

Comments
 (0)