Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Handler to serve a simple time series for all points in a series. | 5 """Handler to serve a simple time series for all points in a series. |
| 6 | 6 |
| 7 This is used to show the revision slider for a chart; it includes data | 7 This is used to show the revision slider for a chart; it includes data |
| 8 for all past points, including those that are not recent. Each entry | 8 for all past points, including those that are not recent. Each entry |
| 9 in the returned list is a 3-item list: [revision, value, timestamp]. | 9 in the returned list is a 3-item list: [revision, value, timestamp]. |
| 10 The revisions and values are used to plot a mini-chart, and the timestamps | 10 The revisions and values are used to plot a mini-chart, and the timestamps |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 def _UpdateCache(test_key): | 72 def _UpdateCache(test_key): |
| 73 """Queries Rows for a test then updates the cache. | 73 """Queries Rows for a test then updates the cache. |
| 74 | 74 |
| 75 Args: | 75 Args: |
| 76 test_key: ndb.Key for a Test entity. | 76 test_key: ndb.Key for a Test entity. |
| 77 | 77 |
| 78 Returns: | 78 Returns: |
| 79 The list of triplets that was just fetched and set in the cache. | 79 The list of triplets that was just fetched and set in the cache. |
| 80 """ | 80 """ |
| 81 if not test_key.get(): | 81 test = test_key.get() |
| 82 # The caching can actually proceed even if the Test entity doesn't exist, | 82 if not test: |
| 83 # but a non-existent Test entity definitely indicates something is wrong. | 83 return |
|
qyearsley
2015/12/28 22:50:56
Should we return [] here? Or explicitly return Non
sullivan
2015/12/29 03:36:07
I changed it to []
| |
| 84 logging.warn('Test not found: %s', utils.TestPath(test_key)) | 84 assert(utils.IsInternalUser() or not test.internal_only) |
| 85 datastore_hooks.SetSinglePrivilegedRequest() | |
| 85 | 86 |
| 86 # A projection query queries just for the values of particular properties; | 87 # A projection query queries just for the values of particular properties; |
| 87 # this is faster than querying for whole entities. | 88 # this is faster than querying for whole entities. |
| 88 query = graph_data.Row.query(projection=['revision', 'value', 'timestamp']) | 89 query = graph_data.Row.query(projection=['revision', 'value', 'timestamp']) |
| 89 query = query.filter(graph_data.Row.parent_test == test_key) | 90 query = query.filter(graph_data.Row.parent_test == test_key) |
| 90 | 91 |
| 91 # Using a large batch_size speeds up queries with > 1000 Rows. | 92 # Using a large batch_size speeds up queries with > 1000 Rows. |
| 92 rows = map(_MakeTriplet, query.iter(batch_size=1000)) | 93 rows = map(_MakeTriplet, query.iter(batch_size=1000)) |
| 94 # Note: Unit tests do not call datastore_hooks with the above query, but | |
| 95 # it is called in production and with more recent SDK. | |
| 96 datastore_hooks.CancelSinglePrivilegedRequest() | |
| 93 SetCache(utils.TestPath(test_key), rows) | 97 SetCache(utils.TestPath(test_key), rows) |
| 94 return rows | 98 return rows |
| 95 | 99 |
| 96 | 100 |
| 97 def _MakeTriplet(row): | 101 def _MakeTriplet(row): |
| 98 """Makes a 3-item list of revision, value and timestamp for a Row.""" | 102 """Makes a 3-item list of revision, value and timestamp for a Row.""" |
| 99 timestamp = utils.TimestampMilliseconds(row.timestamp) | 103 timestamp = utils.TimestampMilliseconds(row.timestamp) |
| 100 return [row.revision, row.value, timestamp] | 104 return [row.revision, row.value, timestamp] |
| 101 | 105 |
| 102 | 106 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 124 revisions = [r[0] for r in graph_rows] | 128 revisions = [r[0] for r in graph_rows] |
| 125 index = bisect.bisect_left(revisions, row.revision) | 129 index = bisect.bisect_left(revisions, row.revision) |
| 126 if index < len(revisions) - 1: | 130 if index < len(revisions) - 1: |
| 127 if revisions[index + 1] == row.revision: | 131 if revisions[index + 1] == row.revision: |
| 128 return # Already in cache. | 132 return # Already in cache. |
| 129 graph_rows.insert(index, _MakeTriplet(row)) | 133 graph_rows.insert(index, _MakeTriplet(row)) |
| 130 | 134 |
| 131 for test_key in test_key_to_rows: | 135 for test_key in test_key_to_rows: |
| 132 graph_rows = test_key_to_rows[test_key] | 136 graph_rows = test_key_to_rows[test_key] |
| 133 SetCache(utils.TestPath(test_key), graph_rows) | 137 SetCache(utils.TestPath(test_key), graph_rows) |
| OLD | NEW |