Fix stats functionality when APC is unavailable.

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Loui Chang 2009-01-08 13:08:58 -05:00
parent 649517ac1f
commit 2da9b55d9f

View file

@ -2,10 +2,10 @@
include_once('aur.inc'); include_once('aur.inc');
$apc_prefix = 'aur:';
# Check if APC extension is loaded # Check if APC extension is loaded
if (!defined('EXTENSION_LOADED_APC')) if (!defined('EXTENSION_LOADED_APC'))
define('EXTENSION_LOADED_APC', extension_loaded('apc')); define('EXTENSION_LOADED_APC', extension_loaded('apc'));
$apc_prefix = 'aur:';
# run a simple db query, retrieving and/or caching the value if APC # run a simple db query, retrieving and/or caching the value if APC
# is available for use # is available for use
@ -17,13 +17,17 @@ function db_cache_value($dbq, $dbh, $key)
$row = mysql_fetch_row($result); $row = mysql_fetch_row($result);
$ret = $row[0]; $ret = $row[0];
# set the TTL here in seconds: 300 seconds = 5 minutes # set the TTL here in seconds: 300 seconds = 5 minutes
apc_store($key, $ret, 300);
if (EXTENSION_LOADED_APC) {
apc_store($key, $ret, 300);
}
} }
return $ret; return $ret;
} }
function updates_table($dbh) function updates_table($dbh)
{ {
global $apc_prefix;
$key = $apc_prefix . 'recent_updates'; $key = $apc_prefix . 'recent_updates';
if(!(EXTENSION_LOADED_APC && ($newest_packages = apc_fetch($key)))) { if(!(EXTENSION_LOADED_APC && ($newest_packages = apc_fetch($key)))) {
$q = 'SELECT * FROM Packages WHERE DummyPkg != 1 ORDER BY GREATEST(SubmittedTS,ModifiedTS) DESC LIMIT 0 , 10'; $q = 'SELECT * FROM Packages WHERE DummyPkg != 1 ORDER BY GREATEST(SubmittedTS,ModifiedTS) DESC LIMIT 0 , 10';
@ -33,7 +37,10 @@ function updates_table($dbh)
while ($row = mysql_fetch_assoc($result)) { while ($row = mysql_fetch_assoc($result)) {
$newest_packages->append($row); $newest_packages->append($row);
} }
apc_store($key, $newest_packages, 300);
if (EXTENSION_LOADED_APC) {
apc_store($key, $newest_packages, 300);
}
} }
include('stats/updates_table.php'); include('stats/updates_table.php');
} }
@ -69,6 +76,7 @@ function user_table($user, $dbh)
function general_stats_table($dbh) function general_stats_table($dbh)
{ {
global $apc_prefix;
# AUR statistics # AUR statistics
$q = "SELECT count(*) FROM Packages,PackageLocations WHERE Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'unsupported'"; $q = "SELECT count(*) FROM Packages,PackageLocations WHERE Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'unsupported'";
$unsupported_count = db_cache_value($q, $dbh, $apc_prefix . 'unsupported_count'); $unsupported_count = db_cache_value($q, $dbh, $apc_prefix . 'unsupported_count');