X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FSiteStatsUpdate.php;h=ab4a609d012ffe2cbca5be69e13d11ec252e9c84;hb=a5be382adfdad4678eec18413c6a118cb3284daf;hp=30aae153dd2830299b4e6b8945590c79d923c76d;hpb=9535f9e4187cd9b7ed6acedbc74a4265ce2d02b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/SiteStatsUpdate.php b/includes/deferred/SiteStatsUpdate.php index 30aae153dd..ab4a609d01 100644 --- a/includes/deferred/SiteStatsUpdate.php +++ b/includes/deferred/SiteStatsUpdate.php @@ -17,26 +17,25 @@ * * @file */ +use Wikimedia\Assert\Assert; /** * Class for handling updates to the site_stats table */ -class SiteStatsUpdate implements DeferrableUpdate { +class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate { /** @var int */ protected $edits = 0; - /** @var int */ protected $pages = 0; - /** @var int */ protected $articles = 0; - /** @var int */ protected $users = 0; - /** @var int */ protected $images = 0; + private static $counters = [ 'edits', 'pages', 'articles', 'users', 'images' ]; + // @todo deprecate this constructor function __construct( $views, $edits, $good, $pages = 0, $users = 0 ) { $this->edits = $edits; @@ -45,6 +44,15 @@ class SiteStatsUpdate implements DeferrableUpdate { $this->users = $users; } + public function merge( MergeableUpdate $update ) { + /** @var SiteStatsUpdate $update */ + Assert::parameterType( __CLASS__, $update, '$update' ); + + foreach ( self::$counters as $field ) { + $this->$field += $update->$field; + } + } + /** * @param array $deltas * @return SiteStatsUpdate @@ -52,8 +60,7 @@ class SiteStatsUpdate implements DeferrableUpdate { public static function factory( array $deltas ) { $update = new self( 0, 0, 0 ); - $fields = [ 'views', 'edits', 'pages', 'articles', 'users', 'images' ]; - foreach ( $fields as $field ) { + foreach ( self::$counters as $field ) { if ( isset( $deltas[$field] ) && $deltas[$field] ) { $update->$field = $deltas[$field]; } @@ -133,7 +140,7 @@ class SiteStatsUpdate implements DeferrableUpdate { */ public static function cacheUpdate( $dbw ) { global $wgActiveUserDays; - $dbr = wfGetDB( DB_SLAVE, 'vslow' ); + $dbr = wfGetDB( DB_REPLICA, 'vslow' ); # Get non-bot users than did some recent action other than making accounts. # If account creation is included, the number gets inflated ~20+ fold on enwiki. $activeUsers = $dbr->selectField(