From fa3c83c114068015697c65b718e652eba7deac74 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Aug 2007 12:27:50 +0000 Subject: [PATCH] Statistics code cleanup, fixed multiple db reload bug. --- includes/SiteStats.php | 16 +++++++++++++++- includes/SpecialStatistics.php | 9 ++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 65e3eb0080..d7b9161ab0 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -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] ) ) { diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index 5fb68f8ffc..6343edd13f 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -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(); -- 2.20.1