$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();
}
}
$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() {