X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FSiteStatsUpdate.php;h=ab4a609d012ffe2cbca5be69e13d11ec252e9c84;hb=97906621aa0a2abc566d831dd83a725c4c13ade1;hp=b8e2726d5afbf62cd2959650103988f00f6f3b85;hpb=bbb705a0b1465725cadccb6da70c1d057b6d1885;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/SiteStatsUpdate.php b/includes/deferred/SiteStatsUpdate.php index b8e2726d5a..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]; } @@ -122,6 +129,9 @@ class SiteStatsUpdate implements DeferrableUpdate { // Commit the updates and unlock the table $dbw->unlock( $lockKey, __METHOD__ ); } + + // Invalid cache used by parser functions + SiteStats::unload(); } /** @@ -130,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( @@ -152,6 +162,9 @@ class SiteStatsUpdate implements DeferrableUpdate { __METHOD__ ); + // Invalid cache used by parser functions + SiteStats::unload(); + return $activeUsers; }