X-Git-Url: http://git.cyclocoop.org/%28%28?a=blobdiff_plain;f=includes%2FSiteStats.php;h=6e2359ae5480899f8e38dabdba69d294192caa51;hb=0d7a30fa27ebaefb5d89693bbe658916b982c082;hp=02e1911d6d933b35dbff7bbaba539a3405dfdc0a;hpb=0fcde42a6ae2dab803f20f67da70545d240eaec8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 02e1911d6d..6e2359ae54 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -226,20 +226,24 @@ class SiteStats { * @return bool */ private static function isSane( $row ) { - if ( - $row === false + if ( $row === false || $row->ss_total_pages < $row->ss_good_articles || $row->ss_total_edits < $row->ss_total_pages + || $row->ss_users < $row->ss_active_users ) { return false; } // Now check for underflow/overflow - foreach ( array( 'total_views', 'total_edits', 'good_articles', - 'total_pages', 'users', 'images' ) as $member ) { - if ( - $row->{"ss_$member"} > 2000000000 - || $row->{"ss_$member"} < 0 - ) { + foreach ( array( + 'ss_total_views', + 'ss_total_edits', + 'ss_good_articles', + 'ss_total_pages', + 'ss_users', + 'ss_active_users', + 'ss_images', + ) as $member ) { + if ( $row->$member > 2000000000 || $row->$member < 0 ) { return false; } } @@ -293,50 +297,56 @@ class SiteStatsUpdate implements DeferrableUpdate { if ( $rate && ( $rate < 0 || mt_rand( 0, $rate - 1 ) != 0 ) ) { $this->doUpdatePendingDeltas(); } else { - $dbw = wfGetDB( DB_MASTER ); - - $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID - if ( $rate ) { - // Lock the table so we don't have double DB/memcached updates - if ( !$dbw->lockIsFree( $lockKey, __METHOD__ ) - || !$dbw->lock( $lockKey, __METHOD__, 1 ) // 1 sec timeout - ) { - $this->doUpdatePendingDeltas(); - return; - } - $pd = $this->getPendingDeltas(); - // Piggy-back the async deltas onto those of this stats update.... - $this->views += ( $pd['ss_total_views']['+'] - $pd['ss_total_views']['-'] ); - $this->edits += ( $pd['ss_total_edits']['+'] - $pd['ss_total_edits']['-'] ); - $this->articles += ( $pd['ss_good_articles']['+'] - $pd['ss_good_articles']['-'] ); - $this->pages += ( $pd['ss_total_pages']['+'] - $pd['ss_total_pages']['-'] ); - $this->users += ( $pd['ss_users']['+'] - $pd['ss_users']['-'] ); - $this->images += ( $pd['ss_images']['+'] - $pd['ss_images']['-'] ); - } - // Need a separate transaction because this a global lock - $dbw->begin( __METHOD__ ); - - // Build up an SQL query of deltas and apply them... - $updates = ''; - $this->appendUpdate( $updates, 'ss_total_views', $this->views ); - $this->appendUpdate( $updates, 'ss_total_edits', $this->edits ); - $this->appendUpdate( $updates, 'ss_good_articles', $this->articles ); - $this->appendUpdate( $updates, 'ss_total_pages', $this->pages ); - $this->appendUpdate( $updates, 'ss_users', $this->users ); - $this->appendUpdate( $updates, 'ss_images', $this->images ); - if ( $updates != '' ) { - $dbw->update( 'site_stats', array( $updates ), array(), __METHOD__ ); - } + wfGetDB( DB_MASTER )->onTransactionIdle( array( $this, 'tryDBUpdateInternal' ) ); + } + } - if ( $rate ) { - // Decrement the async deltas now that we applied them - $this->removePendingDeltas( $pd ); - // Commit the updates and unlock the table - $dbw->unlock( $lockKey, __METHOD__ ); + /** + * Do not call this outside of SiteStatsUpdate + * + * @return void + */ + public function tryDBUpdateInternal() { + global $wgSiteStatsAsyncFactor; + + $dbw = wfGetDB( DB_MASTER ); + $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID + if ( $wgSiteStatsAsyncFactor ) { + // Lock the table so we don't have double DB/memcached updates + if ( !$dbw->lockIsFree( $lockKey, __METHOD__ ) + || !$dbw->lock( $lockKey, __METHOD__, 1 ) // 1 sec timeout + ) { + $this->doUpdatePendingDeltas(); + return; } + $pd = $this->getPendingDeltas(); + // Piggy-back the async deltas onto those of this stats update.... + $this->views += ( $pd['ss_total_views']['+'] - $pd['ss_total_views']['-'] ); + $this->edits += ( $pd['ss_total_edits']['+'] - $pd['ss_total_edits']['-'] ); + $this->articles += ( $pd['ss_good_articles']['+'] - $pd['ss_good_articles']['-'] ); + $this->pages += ( $pd['ss_total_pages']['+'] - $pd['ss_total_pages']['-'] ); + $this->users += ( $pd['ss_users']['+'] - $pd['ss_users']['-'] ); + $this->images += ( $pd['ss_images']['+'] - $pd['ss_images']['-'] ); + } + + // Build up an SQL query of deltas and apply them... + $updates = ''; + $this->appendUpdate( $updates, 'ss_total_views', $this->views ); + $this->appendUpdate( $updates, 'ss_total_edits', $this->edits ); + $this->appendUpdate( $updates, 'ss_good_articles', $this->articles ); + $this->appendUpdate( $updates, 'ss_total_pages', $this->pages ); + $this->appendUpdate( $updates, 'ss_users', $this->users ); + $this->appendUpdate( $updates, 'ss_images', $this->images ); + if ( $updates != '' ) { + $dbw->update( 'site_stats', array( $updates ), array(), __METHOD__ ); + } - $dbw->commit( __METHOD__ ); + if ( $wgSiteStatsAsyncFactor ) { + // Decrement the async deltas now that we applied them + $this->removePendingDeltas( $pd ); + // Commit the updates and unlock the table + $dbw->unlock( $lockKey, __METHOD__ ); } }