mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 17:38:54 +00:00
perf: HTTP caching headers for /api/query_results [fixes #228]
This commit is contained in:
parent
c2d621ae0f
commit
a12b43265d
8
redash/cache.py
Normal file
8
redash/cache.py
Normal file
@ -0,0 +1,8 @@
|
||||
from flask import make_response
|
||||
from functools import update_wrapper
|
||||
|
||||
ONE_YEAR = 60 * 60 * 24 * 365.25
|
||||
|
||||
headers = {
|
||||
'Cache-Control': 'max-age=%d' % ONE_YEAR
|
||||
}
|
@ -26,6 +26,7 @@ from redash.wsgi import app, auth, api
|
||||
import logging
|
||||
from tasks import QueryTask
|
||||
|
||||
from cache import headers as cache_headers
|
||||
|
||||
@app.route('/ping', methods=['GET'])
|
||||
def ping():
|
||||
@ -417,7 +418,8 @@ class QueryResultAPI(BaseResource):
|
||||
def get(self, query_result_id):
|
||||
query_result = models.QueryResult.get_by_id(query_result_id)
|
||||
if query_result:
|
||||
return {'query_result': query_result.to_dict()}
|
||||
data = json.dumps({'query_result': query_result.to_dict()}, cls=utils.JSONEncoder)
|
||||
return make_response(data, 200, cache_headers)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user