From: Tim Starling Date: Fri, 26 Sep 2008 15:35:11 +0000 (+0000) Subject: * Use a separate transaction for the site_stats update X-Git-Tag: 1.31.0-rc.0~45081 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=60fbfaa93f22ea479e3b9f38d99807bf0436dd05;p=lhc%2Fweb%2Fwiklou.git * Use a separate transaction for the site_stats update * Remove obsolete runtime schema check --- diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 2bca25fa20..ab0caa7e04 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -212,44 +212,22 @@ class SiteStatsUpdate { $fname = 'SiteStatsUpdate::doUpdate'; $dbw = wfGetDB( DB_MASTER ); - # First retrieve the row just to find out which schema we're in - $row = $dbw->selectRow( 'site_stats', '*', false, $fname ); - $updates = ''; $this->appendUpdate( $updates, 'ss_total_views', $this->mViews ); $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits ); $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood ); + $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages ); + $this->appendUpdate( $updates, 'ss_users', $this->mUsers ); - if ( isset( $row->ss_total_pages ) ) { - # Update schema if required - if ( $row->ss_total_pages == -1 && !$this->mViews ) { - $dbr = wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') ); - list( $page, $user ) = $dbr->tableNamesN( 'page', 'user' ); - - $sql = "SELECT COUNT(*) AS total FROM $page"; - $res = $dbr->query( $sql, $fname ); - $pageRow = $dbr->fetchObject( $res ); - $pages = $pageRow->total + $this->mPages; - - $sql = "SELECT COUNT(*) AS total FROM $user"; - $res = $dbr->query( $sql, $fname ); - $userRow = $dbr->fetchObject( $res ); - $users = $userRow->total + $this->mUsers; - - if ( $updates ) { - $updates .= ','; - } - $updates .= "ss_total_pages=$pages, ss_users=$users"; - } else { - $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages ); - $this->appendUpdate( $updates, 'ss_users', $this->mUsers ); - } - } if ( $updates ) { $site_stats = $dbw->tableName( 'site_stats' ); $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1); + + # Need a separate transaction because this a global lock + $dbw->begin(); $dbw->query( $sql, $fname ); + $dbw->commit(); } } diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index e43394179b..4980910e86 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1020,13 +1020,16 @@ function do_stats_init() { $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ ); if( $row === false ) { echo "data is missing! rebuilding...\n"; - - global $IP; - require_once "$IP/maintenance/initStats.inc"; - wfInitStats(); + } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) { + echo "missing ss_total_pages, rebuilding...\n"; } else { echo "ok.\n"; + return; } + + global $IP; + require_once "$IP/maintenance/initStats.inc"; + wfInitStats(); } function do_active_users_init() {