user web: change remaining occurrences of fullpage caching to object cache. start_cache() and end_cache() are now deprecated.

svn path=/trunk/boinc/; revision=23230
This commit is contained in:
Rytis Slatkevičius 2011-03-13 20:05:25 +00:00
parent e858e7bcfa
commit c819d552c0
7 changed files with 142 additions and 101 deletions

View File

@ -1581,8 +1581,22 @@ Rytis 12 Mar 2011
top_users.php top_users.php
view_profile.php view_profile.php
David 12 Mar 2001 David 12 Mar 2011
- move client simulator PHP code to doc/sim - move client simulator PHP code to doc/sim
doc/sim/ doc/sim/
various various
Rytis 13 Mar 2011
- user web: change remaining occurrences of fullpage caching to object
cache. start_cache() and end_cache() are now deprecated.
html/
inc/
cache.inc
team.inc
user/
download_network.php
server_status.php
team_members.php
userw.php

View File

@ -167,8 +167,10 @@ function get_cached_data($max_age, $params=""){
if ($max_age) { if ($max_age) {
if (defined('MEMCACHE_SERVERS')) { if (defined('MEMCACHE_SERVERS')) {
$cache = BoincMemcache::get()->get($path); $cache = BoincMemcache::get()->get($path);
if ($cache) { if ($cache['content']) {
return $cache->content; return $cache['content'];
} else {
return $cache;
} }
} else { } else {
cache_check_diskspace(); cache_check_diskspace();
@ -181,6 +183,7 @@ function get_cached_data($max_age, $params=""){
return false; //No data was cached, just return return false; //No data was cached, just return
} }
// DEPRECATED
function start_cache($max_age, $params=""){ function start_cache($max_age, $params=""){
global $no_cache, $caching, $memcache; global $no_cache, $caching, $memcache;
@ -242,7 +245,7 @@ function start_cache($max_age, $params=""){
} }
// write output buffer both to client and to cache // write output buffer both to client and to cache
// // DEPRECATED
function end_cache($max_age,$params=""){ function end_cache($max_age,$params=""){
global $no_cache; global $no_cache;
if ($no_cache) return; if ($no_cache) return;
@ -276,8 +279,7 @@ function set_cached_data($max_age, $data, $params=""){
$path = get_path($params); $path = get_path($params);
if (defined('MEMCACHE_SERVERS')) { if (defined('MEMCACHE_SERVERS')) {
$cache = array('content' => $data, 'timestamp' => time()); $cache = array('content' => $data, 'timestamp' => time());
ob_end_flush(); BoincMemcache::get()->set($path, $cache, $max_age);
$cache = BoincMemcache::get()->set($path, $cache, $max_age);
} else { } else {
$fhandle = fopen($path, "w"); $fhandle = fopen($path, "w");
fwrite($fhandle, $data); fwrite($fhandle, $data);

View File

@ -225,11 +225,16 @@ function display_team_members($team, $offset, $sort_by) {
<th>'.tra('Country').'</th> <th>'.tra('Country').'</th>
</tr> </tr>
'; ';
if ($nosort) { $cache_args = "teamid=".$team->id."&mosort=".$nosort."&order=".$sort_clause."&limit=".$offset."_".$n;
$users = BoincUser::enum("teamid=$team->id limit $offset,$n"); $users = unserialize(get_cached_data(TEAM_PAGE_TTL, $cache_args));
} else { if (!$users) {
$users = BoincUser::enum("teamid=$team->id order by $sort_clause limit $offset,$n"); if ($nosort) {
$users = BoincUser::enum("teamid=$team->id limit $offset,$n");
} else {
$users = BoincUser::enum("teamid=$team->id order by $sort_clause limit $offset,$n");
}
set_cached_data(TEAM_PAGE_TTL, serialize($users), $cache_args);
} }
$j = $offset + 1; $j = $offset + 1;

View File

@ -22,7 +22,6 @@ require_once("../inc/cache.inc");
check_get_args(array()); check_get_args(array());
start_cache(3600);
page_head(tra("Download BOINC add-on software")); page_head(tra("Download BOINC add-on software"));
echo " echo "
<p>" . <p>" .
@ -40,17 +39,18 @@ If this is not enough you should contact the author.").
</ul> </ul>
"; ";
$httpFile = @fopen("http://boinc.berkeley.edu/addons.php?strip_header=true", "rb"); $httpFile = unserialize(get_cached_data(3600));
if (!$httpFile){ if (!$httpFile) {
echo ""; $httpFile = @file_get_contents("http://boinc.berkeley.edu/addons.php?strip_header=true");
} else { if ($httpFile) {
fpassthru($httpFile); set_cached_data(3600, serialize($httpFile));
fclose($httpFile); }
} }
echo $httpFile;
echo " echo "
<p><p> <p><p>
"; ";
page_tail(); page_tail();
end_cache(3600);
?> ?>

View File

@ -58,11 +58,6 @@ check_get_args(array("xml"));
$xml = get_int("xml", true); $xml = get_int("xml", true);
$cache_args = $languages_in_use[0];
if ($xml) $cache_args = "xml=1";
$cache_period = 3600;
start_cache($cache_period, $cache_args);
// daemon status outputs: 1 (running) 0 (not running) or -1 (disabled) // daemon status outputs: 1 (running) 0 (not running) or -1 (disabled)
// //
function daemon_status($host, $pidname, $progname, $disabled) { function daemon_status($host, $pidname, $progname, $disabled) {
@ -128,45 +123,68 @@ function show_counts($key, $xmlkey, $value) {
return 0; return 0;
} }
function get_mysql_count ($query) { function get_mysql_count($query) {
$result = mysql_query("select count(*) as count from " . $query); $count = unserialize(get_cached_data(3600, "get_mysql_count".$query));
$count = mysql_fetch_object($result); if ($count == false) {
mysql_free_result($result); $result = mysql_query("select count(*) as count from " . $query);
return $count->count; $count = mysql_fetch_object($result);
mysql_free_result($result);
$count = $count->count;
set_cached_data(3600, serialize($count), "get_mysql_count".$query);
}
return $count;
} }
function get_mysql_value ($query) { function get_mysql_value($query) {
$result = mysql_query($query); $value = unserialize(get_cached_data(3600, "get_mysql_value".$query));
$row = mysql_fetch_object($result); if ($value == false) {
mysql_free_result($result); $result = mysql_query($query);
return $row->value; $row = mysql_fetch_object($result);
mysql_free_result($result);
$value = $row->value;
set_cached_data(3600, serialize($value), "get_mysql_value".$query);
}
return $value;
} }
function get_mysql_assoc($query) { function get_mysql_assoc($query) {
$sql = "SELECT * FROM app WHERE deprecated != 1"; $assoc = unserialize(get_cached_data(3600, "get_mysql_assoc".$query));
$result = mysql_query($sql); if ($assoc == false) {
while($row = mysql_fetch_assoc($result)) { $sql = "SELECT * FROM app WHERE deprecated != 1";
$assoc[] = $row; $result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
$assoc[] = $row;
}
mysql_free_result($result);
set_cached_data(3600, serialize($assoc), "get_mysql_assoc".$query);
} }
mysql_free_result($result);
return $assoc; return $assoc;
} }
function get_mysql_user ($clause) { function get_mysql_user($clause) {
$result = mysql_query("select count(userid) as userid from (SELECT distinct userid FROM result where validate_state=1 and received_time > (unix_timestamp()-(3600*24*1)) " . $clause . ") t"); $count = unserialize(get_cached_data(3600, "get_mysql_user".$clause));
$count = mysql_fetch_object($result); if ($count == false) {
mysql_free_result($result); $result = mysql_query("select count(userid) as userid from (SELECT distinct userid FROM result where validate_state=1 and received_time > (unix_timestamp()-(3600*24*1)) " . $clause . ") t");
return $count->userid; $count = mysql_fetch_object($result);
mysql_free_result($result);
$count = $count->userid;
set_cached_data(3600, serialize($count), "get_mysql_user".$clause);
}
return $count;
} }
function get_cpu_time ($appid) { function get_cpu_time($appid) {
$result = mysql_query(" $count = unserialize(get_cached_data(3600, "get_cpu_time".$appid));
Select ceil(avg(cpu_time)/3600*100)/100 as cpu_time, if ($count == false) {
ceil(min(cpu_time)/3600*100)/100 as min, $result = mysql_query("
ceil(max(cpu_time)/3600*100)/100 as max Select ceil(avg(cpu_time)/3600*100)/100 as cpu_time,
from (SELECT cpu_time FROM `result` WHERE appid = $appid and validate_state =1 and received_time > (unix_timestamp()-(3600*24)) ORDER BY `received_time` DESC limit 100) t"); ceil(min(cpu_time)/3600*100)/100 as min,
$count = mysql_fetch_object($result); ceil(max(cpu_time)/3600*100)/100 as max
mysql_free_result($result); from (SELECT cpu_time FROM `result` WHERE appid = $appid and validate_state =1 and received_time > (unix_timestamp()-(3600*24)) ORDER BY `received_time` DESC limit 100) t");
$count = mysql_fetch_object($result);
mysql_free_result($result);
set_cached_data(3600, serialize($count), "get_cpu_time".$appid);
}
return $count; return $count;
} }
@ -340,12 +358,16 @@ if ($retval) {
get_mysql_count("result where file_delete_state=1") get_mysql_count("result where file_delete_state=1")
); );
$result = mysql_query("select MIN(transition_time) as min from workunit"); $gap = unserialize(get_cached_data(3600, "transitioner_backlog"));
$min = mysql_fetch_object($result); if ($gap === false) {
mysql_free_result($result); $result = mysql_query("select MIN(transition_time) as min from workunit");
$gap = (time() - $min->min)/3600; $min = mysql_fetch_object($result);
if (($gap < 0) || ($min->min == 0)) { mysql_free_result($result);
$gap = 0; $gap = (time() - $min->min)/3600;
if (($gap < 0) || ($min->min == 0)) {
$gap = 0;
}
set_cached_data(3600, serialize($gap), "transitioner_backlog");
} }
show_counts( show_counts(
tra("Transitioner backlog (hours)"), tra("Transitioner backlog (hours)"),
@ -441,5 +463,4 @@ if ($xml) {
page_tail(); page_tail();
} }
end_cache($cache_period, $cache_args);
?> ?>

View File

@ -37,15 +37,15 @@ if ($offset > 1000) {
$teamid = get_int("teamid"); $teamid = get_int("teamid");
$cache_args = "teamid=$teamid&offset=$offset&sort_by=$sort_by"; $cache_args = "teamid=$teamid";
start_cache(TEAM_PAGE_TTL, $cache_args); $team = unserialize(get_cached_data(TEAM_PAGE_TTL, $cache_args));
if (!$team) {
$team = BoincTeam::lookup_id($teamid); $team = BoincTeam::lookup_id($teamid);
set_cached_data(TEAM_PAGE_TTL, serialize($team), $cache_args);
}
page_head(tra("Members of %1", "<a href=team_display.php?teamid=$teamid>$team->name</a>")); page_head(tra("Members of %1", "<a href=team_display.php?teamid=$teamid>$team->name</a>"));
display_team_members($team, $offset, $sort_by); display_team_members($team, $offset, $sort_by);
page_tail(); page_tail();
end_cache(TEAM_PAGE_TTL, $cache_args);
?> ?>

View File

@ -17,9 +17,7 @@
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/util.inc"); require_once("../inc/util.inc");
require_once("../inc/db.inc");
require_once("../inc/wap.inc"); require_once("../inc/wap.inc");
require_once("../inc/cache.inc");
check_get_args(array("id")); check_get_args(array("id"));
@ -29,45 +27,46 @@ function show_credit_wap($user) {
return $retstr; return $retstr;
} }
function show_user_wap($user) { function show_user_wap($userid) {
wap_begin(); wap_begin();
if (!$user) {
echo "<br/>".tra("User not found!")."<br/>"; $cache = unserialize(get_cached_data(USER_PAGE_TTL, "userid=".$userid));
wap_end(); if (!$cache) {
return; $cache = new stdClass;
} $cache->user = BoincUser::lookup_id($userid);
if ($cache->user->teamid) {
$cache->team = BoincTeam::lookup_id($cache->user->teamid);
}
$cache->wap_timestamp = wap_timestamp();
set_cached_data(USER_PAGE_TTL, serialize($cache), "userid=".$userid);
}
if (!$cache->user) {
echo "<br/>".tra("User not found!")."<br/>";
wap_end();
return;
}
// keep a 'running tab' in wapstr in case exceeds 1K WAP limit // keep a 'running tab' in wapstr in case exceeds 1K WAP limit
$wapstr = PROJECT."<br/>".tra("Account Data<br/>for %1<br/>Time:", $cache->user->name)." ".$cache->wap_timestamp;
$wapstr = PROJECT . "<br/>".tra("Account Data<br/>for %1<br/>Time:", $user->name)." " . wap_timestamp(); $wapstr .= show_credit_wap($cache->user);
$wapstr .= show_credit_wap($user); if ($cache->user->teamid) {
if ($user->teamid) { $wapstr .= "<br/>".tra("Team:")." ".$cache->team->name."<br/>";
$team = BoincTeam::lookup_id($user->teamid); $wapstr .= tra("Team TotCred:")." " . format_credit($cache->team->total_credit) . "<br/>";
$wapstr .= "<br/>".tra("Team:")." $team->name<br/>"; $wapstr .= tra("Team AvgCred:")." " . format_credit($cache->team->expavg_credit) . "<br/>";
$wapstr .= tra("Team TotCred:")." " . format_credit($team->total_credit) . "<br/>";
$wapstr .= tra("Team AvgCred:")." " . format_credit($team->expavg_credit) . "<br/>";
} else { } else {
$wapstr .= "<br/>".tra("Team: None")."<br/>"; $wapstr .= "<br/>".tra("Team: None")."<br/>";
} }
// don't want to send more than 1KB probably? // don't want to send more than 1KB probably?
if (strlen($wapstr)>1024) { if (strlen($wapstr) > 1024) {
echo substr($wapstr,0,1024); $wapstr = substr($wapstr, 0, 1024);
} else { }
echo $wapstr;
} echo $wapstr;
wap_end();
wap_end();
} }
$userid = get_int('id'); show_user_wap(get_int('id'));
$cache_args = "userid=".$userid;
start_cache(USER_PAGE_TTL, $cache_args);
$user = BoincUser::lookup_id($userid);
show_user_wap($user);
end_cache(USER_PAGE_TTL, $cache_args);
?> ?>