Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316310

Change subject: Avoid unnecessary diffing/patching in SubmitEntityAction
......................................................................

Avoid unnecessary diffing/patching in SubmitEntityAction

Bug: T147631
Change-Id: Ib942de3c6a7f15dca118c9daa6a5bf8e5fea753b
---
M repo/includes/Actions/SubmitEntityAction.php
1 file changed, 30 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/10/316310/1

diff --git a/repo/includes/Actions/SubmitEntityAction.php 
b/repo/includes/Actions/SubmitEntityAction.php
index 46fcc1a..95291e2 100644
--- a/repo/includes/Actions/SubmitEntityAction.php
+++ b/repo/includes/Actions/SubmitEntityAction.php
@@ -111,18 +111,8 @@
                 * @var Revision $latestRevision
                 */
                list( $olderRevision, $newerRevision, $latestRevision ) = 
$revisions->getValue();
-
-               /**
-                * @var EntityContent $latestContent
-                * @var EntityContent $olderContent
-                * @var EntityContent $newerContent
-                */
-               $olderContent = $olderRevision->getContent();
-               $newerContent = $newerRevision->getContent();
+               $patchedContent = $this->patchContent( $olderRevision, 
$newerRevision, $latestRevision );
                $latestContent = $latestRevision->getContent();
-
-               $diff = $newerContent->getDiff( $olderContent );
-               $patchedContent = $latestContent->getPatchedCopy( $diff );
 
                if ( $patchedContent->equals( $latestContent ) ) {
                        $status = Status::newGood();
@@ -148,6 +138,35 @@
        }
 
        /**
+        * @param Revision $olderRevision
+        * @param Revision $newerRevision
+        * @param Revision $latestRevision
+        *
+        * @return EntityContent
+        */
+       private function patchContent(
+               Revision $olderRevision,
+               Revision $newerRevision,
+               Revision $latestRevision
+       ) {
+               /**
+                * @var EntityContent $olderContent
+                * @var EntityContent $newerContent
+                * @var EntityContent $latestContent
+                */
+               $olderContent = $olderRevision->getContent();
+               $newerContent = $newerRevision->getContent();
+               $latestContent = $latestRevision->getContent();
+
+               // Skip diffing and patching when possible for performance 
reasons
+               if ( $newerRevision->getId() === $latestRevision->getId() ) {
+                       return $latestContent;
+               }
+
+               return $latestContent->getPatchedCopy( $newerContent->getDiff( 
$olderContent ) );
+       }
+
+       /**
         * @param string $actionName
         * @param Revision $revision
         * @param string $userSummary

-- 
To view, visit https://gerrit.wikimedia.org/r/316310
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib942de3c6a7f15dca118c9daa6a5bf8e5fea753b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to