From 5010f58770450838e2cc7342c6f18d72f612f2dc Mon Sep 17 00:00:00 2001 From: "rniwa@webkit.org" Date: Fri, 9 Jan 2015 22:39:33 +0000 Subject: [PATCH] Cache-control should be set only on api/runs https://bugs.webkit.org/show_bug.cgi?id=140312 Reviewed by Andreas Kling. Some JSON APIs such as api/analysis-tasks can't be cached even for a short period of time (e.g. a few minutes) since they can be modified by the user on demand. Since only api/runs.php takes a long time to generate JSONs, just set cache-control there instead of json-header.php which is used by other JSON APIs. Also set date_default_timezone_set in db.php since we never use non-UTC timezone in our scripts. * public/api/analysis-tasks.php: * public/api/runs.php: Set the cache control headers. * public/api/test-groups.php: * public/include/db.php: Set the default timezone to UTC. * public/include/json-header.php: Don't set the cache control headers. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@178208 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Websites/perf.webkit.org/ChangeLog | 19 +++++++++++++++++++ .../public/api/analysis-tasks.php | 1 - Websites/perf.webkit.org/public/api/runs.php | 6 +++++- .../public/api/test-groups.php | 1 - .../perf.webkit.org/public/include/db.php | 2 ++ .../public/include/json-header.php | 3 --- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Websites/perf.webkit.org/ChangeLog b/Websites/perf.webkit.org/ChangeLog index 4f59d4ec55b6..a5fb972a2b61 100644 --- a/Websites/perf.webkit.org/ChangeLog +++ b/Websites/perf.webkit.org/ChangeLog @@ -1,3 +1,22 @@ +2015-01-09 Ryosuke Niwa + + Cache-control should be set only on api/runs + https://bugs.webkit.org/show_bug.cgi?id=140312 + + Reviewed by Andreas Kling. + + Some JSON APIs such as api/analysis-tasks can't be cached even for a short period of time (e.g. a few minutes) + since they can be modified by the user on demand. Since only api/runs.php takes a long time to generate JSONs, + just set cache-control there instead of json-header.php which is used by other JSON APIs. + + Also set date_default_timezone_set in db.php since we never use non-UTC timezone in our scripts. + + * public/api/analysis-tasks.php: + * public/api/runs.php: Set the cache control headers. + * public/api/test-groups.php: + * public/include/db.php: Set the default timezone to UTC. + * public/include/json-header.php: Don't set the cache control headers. + 2015-01-09 Ryosuke Niwa api/report-commit should authenticate with a slave name and password diff --git a/Websites/perf.webkit.org/public/api/analysis-tasks.php b/Websites/perf.webkit.org/public/api/analysis-tasks.php index 82c9cda638c3..1967b6293321 100644 --- a/Websites/perf.webkit.org/public/api/analysis-tasks.php +++ b/Websites/perf.webkit.org/public/api/analysis-tasks.php @@ -60,7 +60,6 @@ function fetch_and_push_bugs_to_tasks($db, &$tasks) { return $bugs; } -date_default_timezone_set('UTC'); function format_task($task_row) { return array( 'id' => $task_row['task_id'], diff --git a/Websites/perf.webkit.org/public/api/runs.php b/Websites/perf.webkit.org/public/api/runs.php index adfa166b0836..31cfa87efe74 100644 --- a/Websites/perf.webkit.org/public/api/runs.php +++ b/Websites/perf.webkit.org/public/api/runs.php @@ -15,6 +15,11 @@ $db = new Database; if (!$db->connect()) exit_with_error('DatabaseConnectionFailure'); +// FIXME: We should support revalication as well as caching results in the server side. +$maxage = config('jsonCacheMaxAge'); +header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); +header("Cache-Control: maxage=$maxage"); + $platform_id = intval($parts[0]); $metric_id = intval($parts[1]); $config_rows = $db->query_and_fetch_all('SELECT config_id, config_type, config_platform, config_metric @@ -47,7 +52,6 @@ function fetch_runs_for_config($db, $config) { return $formatted_runs; } -date_default_timezone_set('UTC'); function parse_revisions_array($postgres_array) { global $repository_id_to_name; diff --git a/Websites/perf.webkit.org/public/api/test-groups.php b/Websites/perf.webkit.org/public/api/test-groups.php index 3d7390abd602..ab01ae90d0bd 100644 --- a/Websites/perf.webkit.org/public/api/test-groups.php +++ b/Websites/perf.webkit.org/public/api/test-groups.php @@ -58,7 +58,6 @@ function fetch_build_requests_for_group($db, $test_group_id) { WHERE request_build = build_id AND request_group = $1 ORDER BY request_order', array($test_group_id)); } -date_default_timezone_set('UTC'); function format_test_group($group_row) { return array( 'id' => $group_row['testgroup_id'], diff --git a/Websites/perf.webkit.org/public/include/db.php b/Websites/perf.webkit.org/public/include/db.php index 1af4465ba3b0..0fe3d954cd07 100644 --- a/Websites/perf.webkit.org/public/include/db.php +++ b/Websites/perf.webkit.org/public/include/db.php @@ -40,6 +40,8 @@ if (config('debug')) { } else error_reporting(E_ERROR); +date_default_timezone_set('UTC'); + class Database { private $connection = false; diff --git a/Websites/perf.webkit.org/public/include/json-header.php b/Websites/perf.webkit.org/public/include/json-header.php index 07ad8e85972b..b52626ed9331 100644 --- a/Websites/perf.webkit.org/public/include/json-header.php +++ b/Websites/perf.webkit.org/public/include/json-header.php @@ -3,9 +3,6 @@ require_once('db.php'); header('Content-type: application/json'); -$maxage = config('jsonCacheMaxAge'); -header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); -header("Cache-Control: maxage=$maxage"); function exit_with_error($status, $details = array()) { $details['status'] = $status; -- 2.36.0