Statistics code cleanup, fixed multiple db reload bug.
This commit is contained in:
parent
1a0e481f85
commit
fa3c83c114
2 changed files with 17 additions and 8 deletions
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
class SiteStats {
|
||||
static $row, $loaded = false;
|
||||
static $admins;
|
||||
static $admins, $jobs;
|
||||
static $pageCount = array();
|
||||
|
||||
static function recache() {
|
||||
|
|
@ -27,6 +27,8 @@ class SiteStats {
|
|||
$dbr = wfGetDB( DB_SLAVE );
|
||||
self::$row = $dbr->selectRow( 'site_stats', '*', false, __METHOD__ );
|
||||
}
|
||||
|
||||
self::$loaded = true;
|
||||
}
|
||||
|
||||
static function loadAndLazyInit() {
|
||||
|
|
@ -104,6 +106,18 @@ class SiteStats {
|
|||
return self::$admins;
|
||||
}
|
||||
|
||||
static function jobs() {
|
||||
if ( !isset( self::$jobs ) ) {
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
self::$jobs = $dbr->estimateRowCount('job');
|
||||
/* Zero rows still do single row read for row that doesn't exist, but people are annoyed by that */
|
||||
if (self::$jobs == 1) {
|
||||
self::$jobs = 0;
|
||||
}
|
||||
}
|
||||
return self::$jobs;
|
||||
}
|
||||
|
||||
static function pagesInNs( $ns ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
if( !isset( self::$pageCount[$ns] ) ) {
|
||||
|
|
|
|||
|
|
@ -21,13 +21,8 @@ function wfSpecialStatistics() {
|
|||
$images = SiteStats::images();
|
||||
$total = SiteStats::pages();
|
||||
$users = SiteStats::users();
|
||||
|
||||
$admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
|
||||
$numJobs = $dbr->estimateRowCount('job');
|
||||
/* Zero rows still do single row read for row that doesn't exist, but people are annoyed by that */
|
||||
if ($numJobs == 1) {
|
||||
$numJobs = 0;
|
||||
}
|
||||
$admins = SiteStats::admins();
|
||||
$numJobs = SiteStats::jobs();
|
||||
|
||||
if ($action == 'raw') {
|
||||
$wgOut->disable();
|
||||
|
|
|
|||
Loading…
Reference in a new issue