From 853de1f5f0ba57fd9aaa37880ff2ac4476bad679 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 17 Mar 2017 11:44:07 -0700 Subject: [PATCH] web: code cleanup Note: the top_*.php pages should be changed so that they cache the entire 10000 items as a unit. Otherwise there could be inconsistency. --- html/user/top_hosts.php | 12 ++---------- html/user/top_teams.php | 14 ++------------ 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/html/user/top_hosts.php b/html/user/top_hosts.php index 60d2131e08..2867b54228 100644 --- a/html/user/top_hosts.php +++ b/html/user/top_hosts.php @@ -42,14 +42,6 @@ function get_top_hosts($offset, $sort_by) { return BoincHost::enum(null, "order by $sort_order limit $offset, $hosts_per_page"); } -function hosts_to_store($participants){ - return serialize($participants); -} - -function store_to_hosts($data){ - return unserialize($data); -} - $sort_by = get_str("sort_by", true); switch ($sort_by) { case "total_credit": @@ -70,10 +62,10 @@ if ($offset >= ITEM_LIMIT) { $cache_args = "sort_by=$sort_by&offset=$offset"; $cacheddata = get_cached_data(TOP_PAGES_TTL, $cache_args); if ($cacheddata){ - $data = store_to_hosts($cacheddata); + $data = unserialize($cacheddata); } else { $data = get_top_hosts($offset,$sort_by); - set_cached_data(TOP_PAGES_TTL, hosts_to_store($data), $cache_args); + set_cached_data(TOP_PAGES_TTL, serialize($data), $cache_args); }; diff --git a/html/user/top_teams.php b/html/user/top_teams.php index 2bdaf5389b..94e3efaafa 100644 --- a/html/user/top_teams.php +++ b/html/user/top_teams.php @@ -47,16 +47,6 @@ function get_top_teams($offset, $sort_by, $type){ return BoincTeam::enum($type_clause, "order by $sort_order limit $offset, $teams_per_page"); } -// These converter functions are here in case we later decide to use something -// else than serializing to save temp data -// -function teams_to_store($participants){ - return serialize($participants); -} -function store_to_teams($data){ - return unserialize($data); -} - $sort_by = get_str("sort_by", true); switch ($sort_by) { case "total_credit": @@ -86,7 +76,7 @@ if ($offset < ITEM_LIMIT) { $cacheddata = get_cached_data(TOP_PAGES_TTL,$cache_args); //If we have got the data in cache if ($cacheddata){ - $data = store_to_teams($cacheddata); // use the cached data + $data = unserialize($cacheddata); // use the cached data } else { //if not do queries etc to generate new data $data = get_top_teams($offset,$sort_by,$type); @@ -96,7 +86,7 @@ if ($offset < ITEM_LIMIT) { $team->nusers = team_count_members($team->id); } //save data in cache - set_cached_data(TOP_PAGES_TTL, teams_to_store($data), $cache_args); + set_cached_data(TOP_PAGES_TTL, serialize($data), $cache_args); } } else { error_page(tra("Limit exceeded - Sorry, first %1 items only", ITEM_LIMIT));