Add caching on get_test_runs_by_build_name
This commit enables simple caching on the results from the get_test_runs_by_build_name. This API call involves one of the slowest subunit2sql DB calls we make and is a good candidate for caching. Right now, we just cache on name and the request datestamps which will result in a lot of potential cache misses as people request varied dates and/or build_names. So there is probably room for additional optimizations in the future. Change-Id: I7582188f4f027bc86375056e5cf60cca3a760ce8
This commit is contained in:
parent
0530b663d1
commit
3ed878f6b8
@ -251,23 +251,30 @@ def _group_runs_by_key(runs_by_time, groupby_key):
|
||||
|
||||
@app.route('/build_name/<string:build_name>/test_runs', methods=['GET'])
|
||||
def get_test_runs_by_build_name(build_name):
|
||||
key = 'build_name'
|
||||
value = parse.unquote(build_name)
|
||||
if not key or not value:
|
||||
return 'A key and value must be specified', 400
|
||||
if not value:
|
||||
return 'A build name must be specified', 400
|
||||
start_date = _parse_datetimes(flask.request.args.get('start_date', None))
|
||||
stop_date = _parse_datetimes(flask.request.args.get('stop_date', None))
|
||||
datetime_resolution = flask.request.args.get('datetime_resolution', 'sec')
|
||||
if datetime_resolution not in ['sec', 'min', 'hour', 'day']:
|
||||
return ('Datetime resolution: %s, is not a valid'
|
||||
' choice' % datetime_resolution), 400
|
||||
|
||||
@region.cache_on_arguments()
|
||||
def _query_test_runs_by_build_name(name, start_date, stop_date):
|
||||
with session_scope() as session:
|
||||
tests = api.get_test_run_dict_by_run_meta_key_value(key, value,
|
||||
tests = api.get_test_run_dict_by_run_meta_key_value('build_name',
|
||||
name,
|
||||
start_date,
|
||||
stop_date, session)
|
||||
stop_date,
|
||||
session)
|
||||
tests = test_run_aggregator.TestRunAggregator(tests).aggregate(
|
||||
datetime_resolution=datetime_resolution)
|
||||
return jsonify({'tests': tests})
|
||||
return tests
|
||||
|
||||
output = _query_test_runs_by_build_name(value, start_date, stop_date)
|
||||
return jsonify({'tests': output})
|
||||
|
||||
|
||||
@app.route('/runs', methods=['GET'])
|
||||
|
@ -87,6 +87,9 @@ class TestRestAPI(base.TestCase):
|
||||
'stop_time': timestamp_b}
|
||||
])
|
||||
def test_get_test_runs_by_build_name(self, api_mock):
|
||||
api.region = mock.MagicMock()
|
||||
api.region.cache_on_arguments = mock.MagicMock()
|
||||
api.region.cache_on_arguments.return_value = lambda x: x
|
||||
res = self.app.get('/build_name/fake_tests/test_runs')
|
||||
self.assertEqual(200, res.status_code)
|
||||
api_mock.assert_called_once_with('build_name', 'fake_tests', None,
|
||||
|
Loading…
Reference in New Issue
Block a user