Adrian Lang has uploaded a new change for review.
https://gerrit.wikimedia.org/r/197873
Change subject: Simplify EntityId handling in ChangeRunCoalescer
......................................................................
Simplify EntityId handling in ChangeRunCoalescer
Since changes are grouped by EntityId anyway, we don't have to check the ids
all the time.
Change-Id: Iefe11e8ca1708c17291a2d2ddaaf8751ff0e4a1a
---
M client/includes/Changes/ChangeRunCoalescer.php
1 file changed, 10 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/73/197873/1
diff --git a/client/includes/Changes/ChangeRunCoalescer.php
b/client/includes/Changes/ChangeRunCoalescer.php
index f5f9e11..d9def26 100644
--- a/client/includes/Changes/ChangeRunCoalescer.php
+++ b/client/includes/Changes/ChangeRunCoalescer.php
@@ -5,6 +5,7 @@
use Exception;
use MWException;
use Wikibase\Change;
+use Wikibase\DataModel\Entity\EntityId;
use Wikibase\EntityChange;
use Wikibase\ItemChange;
use Wikibase\Lib\Changes\EntityChangeFactory;
@@ -66,7 +67,7 @@
$changesByEntity = $this->groupChangesByEntity( $changes );
foreach ( $changesByEntity as $entityChanges ) {
- $entityChanges = $this->coalesceRuns( $entityChanges );
+ $entityChanges = $this->coalesceRuns(
$entityChanges[0]->getEntityId(), $entityChanges );
$coalesced = array_merge( $coalesced, $entityChanges );
}
@@ -110,12 +111,13 @@
* If $changes is empty, this method returns null. If $changes contains
exactly one change,
* that change is returned. Otherwise, a combined change is returned.
*
+ * @param EntityId $entityId
* @param EntityChange[] $changes The changes to combine.
*
* @throws MWException
* @return Change a combined change representing the activity from all
the original changes.
*/
- private function mergeChanges( array $changes ) {
+ private function mergeChanges( EntityId $entityId, array $changes ) {
if ( empty( $changes ) ) {
return null;
} elseif ( count( $changes ) === 1 ) {
@@ -146,8 +148,6 @@
$lastmeta = $last->getMetadata();
$firstmeta = $first->getMetadata();
- $entityId = $first->getEntityId();
-
$parentRevId = $firstmeta['parent_id'];
$latestRevId = $firstmeta['rev_id'];
@@ -171,7 +171,6 @@
array(
'revision_id' => $last->getField( 'revision_id'
),
'user_id' => $last->getField( 'user_id' ),
- 'object_id' => $last->getField( 'object_id' ),
'time' => $last->getField( 'time' ),
)
);
@@ -197,22 +196,20 @@
/**
* Coalesce consecutive changes by the same user to the same entity
into one.
+ *
* A run of changes may be broken if the action performed changes (e.g.
deletion
* instead of update) or if a sitelink pointing to the local wiki was
modified.
*
- * Some types of actions, like deletion, will break runs.
- * Interleaved changes to different items will break runs.
- *
+ * @param EntityId $entityId
* @param EntityChange[] $changes
*
* @return EntityChange[] grouped changes
*/
- private function coalesceRuns( array $changes ) {
+ private function coalesceRuns( EntityId $entityId, array $changes ) {
$coalesced = array();
$currentRun = array();
$currentUser = null;
- $currentEntity = null;
$currentAction = null;
$breakNext = false;
@@ -221,12 +218,10 @@
$action = $change->getAction();
$meta = $change->getMetadata();
$user = $meta['user_text'];
- $entityId =
$change->getEntityId()->__toString();
$break = $breakNext
|| $currentAction !== $action
- || $currentUser !== $user
- || $currentEntity !== $entityId;
+ || $currentUser !== $user;
$breakNext = false;
@@ -245,7 +240,7 @@
if ( $break ) {
if ( !empty( $currentRun ) ) {
try {
- $coalesced[] =
$this->mergeChanges( $currentRun );
+ $coalesced[] =
$this->mergeChanges( $entityId, $currentRun );
} catch ( MWException $ex ) {
// Something went wrong
while trying to merge the changes.
// Just keep the
original run.
@@ -256,7 +251,6 @@
$currentRun = array();
$currentUser = $user;
- $currentEntity = $entityId;
$currentAction = $action ===
EntityChange::ADD ? EntityChange::UPDATE : $action;
}
@@ -269,7 +263,7 @@
if ( !empty( $currentRun ) ) {
try {
- $coalesced[] = $this->mergeChanges( $currentRun
);
+ $coalesced[] = $this->mergeChanges( $entityId,
$currentRun );
} catch ( MWException $ex ) {
// Something went wrong while trying to merge
the changes.
// Just keep the original run.
--
To view, visit https://gerrit.wikimedia.org/r/197873
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefe11e8ca1708c17291a2d2ddaaf8751ff0e4a1a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits