* Use a separate transaction for the site_stats update
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 26 Sep 2008 15:35:11 +0000 (15:35 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 26 Sep 2008 15:35:11 +0000 (15:35 +0000)
* Remove obsolete runtime schema check

includes/SiteStats.php
maintenance/updaters.inc

index 2bca25f..ab0caa7 100644 (file)
@@ -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();
                }
        }
        
index e433941..4980910 100644 (file)
@@ -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() {