summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-01-23 19:32:55 -0600
committerLoui Chang <louipc.ist@gmail.com>2009-01-25 11:41:30 -0500
commit9cf7f1a4a2852275a055f803d0cff991e35b1acc (patch)
treec9920741ba0a412066f91a61a7484116192778a9 /web/lib
parentd6a09ba1a5fdca64abeb920bc2c62a51a48cf348 (diff)
downloadaurweb-9cf7f1a4a2852275a055f803d0cff991e35b1acc.tar.xz
APC work follow-up
I managed to send an outdated patch to the mailing list that got applied, so some of these changes never made it in. A little more cleanup and a little more caching, and also increase the default time to 600 seconds (10 minutes). Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/stats.inc43
1 files changed, 22 insertions, 21 deletions
diff --git a/web/lib/stats.inc b/web/lib/stats.inc
index 7916f05..706027c 100644
--- a/web/lib/stats.inc
+++ b/web/lib/stats.inc
@@ -2,7 +2,10 @@
include_once('aur.inc');
+# APC configuration variables
$apc_prefix = 'aur:';
+$apc_ttl = 600;
+
# Check if APC extension is loaded
if (!defined('EXTENSION_LOADED_APC'))
define('EXTENSION_LOADED_APC', extension_loaded('apc'));
@@ -12,14 +15,17 @@ if (!defined('EXTENSION_LOADED_APC'))
#
function db_cache_value($dbq, $dbh, $key)
{
- if(!(EXTENSION_LOADED_APC && ($ret = apc_fetch($key)))) {
+ global $apc_ttl;
+ $bool = false;
+ if(EXTENSION_LOADED_APC) {
+ $ret = apc_fetch($key, $bool);
+ }
+ if(!$bool) {
$result = db_query($dbq, $dbh);
$row = mysql_fetch_row($result);
$ret = $row[0];
- # set the TTL here in seconds: 300 seconds = 5 minutes
-
if (EXTENSION_LOADED_APC) {
- apc_store($key, $ret, 300);
+ apc_store($key, $ret, $apc_ttl);
}
}
return $ret;
@@ -27,7 +33,7 @@ function db_cache_value($dbq, $dbh, $key)
function updates_table($dbh)
{
- global $apc_prefix;
+ global $apc_prefix, $apc_ttl;
$key = $apc_prefix . 'recent_updates';
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';
@@ -37,9 +43,8 @@ function updates_table($dbh)
while ($row = mysql_fetch_assoc($result)) {
$newest_packages->append($row);
}
-
if (EXTENSION_LOADED_APC) {
- apc_store($key, $newest_packages, 300);
+ apc_store($key, $newest_packages, $apc_ttl);
}
}
include('stats/updates_table.php');
@@ -47,28 +52,24 @@ function updates_table($dbh)
function user_table($user, $dbh)
{
+ global $apc_prefix;
+ $escuser = mysql_real_escape_string($user);
+ $base_q = "SELECT count(*) FROM Packages,PackageLocations,Users WHERE Packages.MaintainerUID = Users.ID AND Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = '%s' AND Users.Username='" . $escuser . "'";
- $base_q = 'SELECT count(*) FROM Packages,PackageLocations,Users WHERE Packages.MaintainerUID = Users.ID AND Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = "%s" AND Users.Username="' .
- mysql_real_escape_string($user).'"';
-
- $result = db_query(sprintf($base_q, 'unsupported'), $dbh);
- $row = mysql_fetch_row($result);
- $maintainer_unsupported_count = $row[0];
+ $maintainer_unsupported_count = db_cache_value(sprintf($base_q, 'unsupported'), $dbh,
+ $apc_prefix . 'user_unsupported_count:' . $escuser);
- $q = "SELECT count(*) FROM Packages,Users WHERE Packages.OutOfDate = 1 AND Packages.MaintainerUID = Users.ID AND Users.Username='" .
- mysql_real_escape_string($user)."'";
+ $q = "SELECT count(*) FROM Packages,Users WHERE Packages.OutOfDate = 1 AND Packages.MaintainerUID = Users.ID AND Users.Username='" . $escuser . "'";
- $result = db_query($q, $dbh);
- $row = mysql_fetch_row($result);
- $flagged_outdated = $row[0];
+ $flagged_outdated = db_cache_value($q, $dbh,
+ $apc_prefix . 'user_flagged_outdated:' . $escuser);
# If the user is a TU calculate the number of the packages
$atype = account_from_sid($_COOKIE["AURSID"]);
if (($atype == 'Trusted User') || ($atype == 'Developer')) {
- $result = db_query(sprintf($base_q, 'community'), $dbh);
- $row = mysql_fetch_row($result);
- $maintainer_community_count = $row[0];
+ $maintainer_community_count = db_cache_value(sprintf($base_q, 'community'), $dbh,
+ $apc_prefix . 'user_community_count:' . $escuser);
}
include('stats/user_table.php');