dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Gallery: Use intrinsic width for gallery to center caption"
[lhc/web/wiklou.git]
/
includes
/
deferred
/
SiteStatsUpdate.php
diff --git
a/includes/deferred/SiteStatsUpdate.php
b/includes/deferred/SiteStatsUpdate.php
index
30aae15
..
ab4a609
100644
(file)
--- a/
includes/deferred/SiteStatsUpdate.php
+++ b/
includes/deferred/SiteStatsUpdate.php
@@
-17,26
+17,25
@@
*
* @file
*/
*
* @file
*/
+use Wikimedia\Assert\Assert;
/**
* Class for handling updates to the site_stats table
*/
/**
* 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 $edits = 0;
-
/** @var int */
protected $pages = 0;
/** @var int */
protected $pages = 0;
-
/** @var int */
protected $articles = 0;
/** @var int */
protected $articles = 0;
-
/** @var int */
protected $users = 0;
/** @var int */
protected $users = 0;
-
/** @var int */
protected $images = 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;
// @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;
}
$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
/**
* @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 );
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];
}
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;
*/
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(
# 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(