Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -1020,13 +1020,16 @@ |
1021 | 1021 | $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ ); |
1022 | 1022 | if( $row === false ) { |
1023 | 1023 | echo "data is missing! rebuilding...\n"; |
1024 | | - |
1025 | | - global $IP; |
1026 | | - require_once "$IP/maintenance/initStats.inc"; |
1027 | | - wfInitStats(); |
| 1024 | + } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) { |
| 1025 | + echo "missing ss_total_pages, rebuilding...\n"; |
1028 | 1026 | } else { |
1029 | 1027 | echo "ok.\n"; |
| 1028 | + return; |
1030 | 1029 | } |
| 1030 | + |
| 1031 | + global $IP; |
| 1032 | + require_once "$IP/maintenance/initStats.inc"; |
| 1033 | + wfInitStats(); |
1031 | 1034 | } |
1032 | 1035 | |
1033 | 1036 | function do_active_users_init() { |
Index: trunk/phase3/includes/SiteStats.php |
— | — | @@ -212,44 +212,22 @@ |
213 | 213 | $fname = 'SiteStatsUpdate::doUpdate'; |
214 | 214 | $dbw = wfGetDB( DB_MASTER ); |
215 | 215 | |
216 | | - # First retrieve the row just to find out which schema we're in |
217 | | - $row = $dbw->selectRow( 'site_stats', '*', false, $fname ); |
218 | | - |
219 | 216 | $updates = ''; |
220 | 217 | |
221 | 218 | $this->appendUpdate( $updates, 'ss_total_views', $this->mViews ); |
222 | 219 | $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits ); |
223 | 220 | $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood ); |
| 221 | + $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages ); |
| 222 | + $this->appendUpdate( $updates, 'ss_users', $this->mUsers ); |
224 | 223 | |
225 | | - if ( isset( $row->ss_total_pages ) ) { |
226 | | - # Update schema if required |
227 | | - if ( $row->ss_total_pages == -1 && !$this->mViews ) { |
228 | | - $dbr = wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') ); |
229 | | - list( $page, $user ) = $dbr->tableNamesN( 'page', 'user' ); |
230 | | - |
231 | | - $sql = "SELECT COUNT(*) AS total FROM $page"; |
232 | | - $res = $dbr->query( $sql, $fname ); |
233 | | - $pageRow = $dbr->fetchObject( $res ); |
234 | | - $pages = $pageRow->total + $this->mPages; |
235 | | - |
236 | | - $sql = "SELECT COUNT(*) AS total FROM $user"; |
237 | | - $res = $dbr->query( $sql, $fname ); |
238 | | - $userRow = $dbr->fetchObject( $res ); |
239 | | - $users = $userRow->total + $this->mUsers; |
240 | | - |
241 | | - if ( $updates ) { |
242 | | - $updates .= ','; |
243 | | - } |
244 | | - $updates .= "ss_total_pages=$pages, ss_users=$users"; |
245 | | - } else { |
246 | | - $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages ); |
247 | | - $this->appendUpdate( $updates, 'ss_users', $this->mUsers ); |
248 | | - } |
249 | | - } |
250 | 224 | if ( $updates ) { |
251 | 225 | $site_stats = $dbw->tableName( 'site_stats' ); |
252 | 226 | $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1); |
| 227 | + |
| 228 | + # Need a separate transaction because this a global lock |
| 229 | + $dbw->begin(); |
253 | 230 | $dbw->query( $sql, $fname ); |
| 231 | + $dbw->commit(); |
254 | 232 | } |
255 | 233 | } |
256 | 234 | |