jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/373040 )

Change subject: Use replica with fallback only if the request got POST'ed
......................................................................


Use replica with fallback only if the request got POST'ed

We assume attemptSave is POST'ed so only use master

Bug: T154555
Change-Id: I1f4f8de5438f1028265b09982514c834e5d85f77
---
M repo/includes/Api/EntitySavingHelper.php
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/Specials/SpecialWikibaseRepoPage.php
M repo/includes/UpdateRepo/UpdateRepoJob.php
5 files changed, 37 insertions(+), 10 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/Api/EntitySavingHelper.php 
b/repo/includes/Api/EntitySavingHelper.php
index 8e6ee33..eeca24c 100644
--- a/repo/includes/Api/EntitySavingHelper.php
+++ b/repo/includes/Api/EntitySavingHelper.php
@@ -337,7 +337,8 @@
                $editEntityHandler = $this->editEntityFactory->newEditEntity(
                        $user,
                        $entity->getId(),
-                       $this->baseRevisionId
+                       $this->baseRevisionId,
+                       true
                );
 
                $token = $this->evaluateTokenParam( $params );
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index c79edfe..ab06d27 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -115,6 +115,11 @@
        private $errorType = 0;
 
        /**
+        * @var bool Can use a master connection or not
+        */
+       private $allowMasterConnection;
+
+       /**
         * indicates a permission error
         */
        const PERMISSION_ERROR = 1;
@@ -184,7 +189,8 @@
                EntityId $entityId = null,
                User $user,
                EditFilterHookRunner $editFilterHookRunner,
-               $baseRevId = 0
+               $baseRevId = 0,
+               $allowMasterConnection = true
        ) {
                $this->entityId = $entityId;
 
@@ -210,6 +216,7 @@
                $this->entityPatcher = $entityPatcher;
 
                $this->editFilterHookRunner = $editFilterHookRunner;
+               $this->allowMasterConnection = $allowMasterConnection;
        }
 
        /**
@@ -276,7 +283,7 @@
                        } elseif ( $id !== null ) {
                                $this->latestRevId = 
(int)$this->entityRevisionLookup->getLatestRevisionId(
                                        $id,
-                                       EntityRevisionLookup::LATEST_FROM_MASTER
+                                       $this->getReplicaMode()
                                );
                        }
                }
@@ -326,10 +333,11 @@
                                $this->baseRev = $this->getLatestRevision();
                        } else {
                                $id = $this->getEntityId();
+
                                $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision(
                                        $id,
                                        $baseRevId,
-                                       
EntityRevisionLookup::LATEST_FROM_REPLICA_WITH_FALLBACK
+                                       $this->getReplicaMode()
                                );
 
                                if ( $this->baseRev === null ) {
@@ -343,6 +351,17 @@
        }
 
        /**
+        * @return string
+        */
+       private function getReplicaMode() {
+               if ( $this->allowMasterConnection === true ) {
+                       return 
EntityRevisionLookup::LATEST_FROM_REPLICA_WITH_FALLBACK;
+               } else {
+                       return EntityRevisionLookup::LATEST_FROM_REPLICA;
+               }
+       }
+
+       /**
         * Get the status object. Only defined after attemptSave() was called.
         *
         * After a successful save, the Status object's value field will 
contain an array,
diff --git a/repo/includes/EditEntityFactory.php 
b/repo/includes/EditEntityFactory.php
index e621c46..3fc1820 100644
--- a/repo/includes/EditEntityFactory.php
+++ b/repo/includes/EditEntityFactory.php
@@ -3,7 +3,6 @@
 namespace Wikibase;
 
 use User;
-use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Services\Diff\EntityDiffer;
 use Wikibase\DataModel\Services\Diff\EntityPatcher;
@@ -84,16 +83,22 @@
        /**
         * @param User $user the user performing the edit
         * @param EntityId|null $entityId the id of the entity to edit
-        * @param int $baseRevId the base revision ID for conflict checking.
+        * @param bool|int $baseRevId the base revision ID for conflict 
checking.
         *        Use 0 to indicate that the current revision should be used as 
the base revision,
         *        effectively disabling conflict detections. true and false 
will be accepted for
         *        backwards compatibility, but both will be treated like 0. 
Note that the behavior
         *        of EditEntity was changed so that "late" conflicts that arise 
between edit conflict
         *        detection and database update are always detected, and result 
in the update to fail.
         *
+        * @param bool $allowMasterConnection Can use a master connection or not
         * @return EditEntity
         */
-       public function newEditEntity( User $user, EntityId $entityId = null, 
$baseRevId = false ) {
+       public function newEditEntity(
+               User $user,
+               EntityId $entityId = null,
+               $baseRevId = false,
+               $allowMasterConnection = true
+       ) {
                return new EditEntity(
                        $this->titleLookup,
                        $this->entityRevisionLookup,
@@ -104,7 +109,8 @@
                        $entityId,
                        $user,
                        $this->editFilterHookRunner,
-                       $baseRevId
+                       $baseRevId,
+                       $allowMasterConnection
                );
        }
 
diff --git a/repo/includes/Specials/SpecialWikibaseRepoPage.php 
b/repo/includes/Specials/SpecialWikibaseRepoPage.php
index 7f02447..87493c3 100644
--- a/repo/includes/Specials/SpecialWikibaseRepoPage.php
+++ b/repo/includes/Specials/SpecialWikibaseRepoPage.php
@@ -82,7 +82,8 @@
                $this->editEntity = $this->editEntityFactory->newEditEntity(
                        $this->getUser(),
                        $id,
-                       $baseRev
+                       $baseRev,
+                       $this->getRequest()->wasPosted()
                );
 
                return $this->editEntity;
diff --git a/repo/includes/UpdateRepo/UpdateRepoJob.php 
b/repo/includes/UpdateRepo/UpdateRepoJob.php
index 8cee916..1924148 100644
--- a/repo/includes/UpdateRepo/UpdateRepoJob.php
+++ b/repo/includes/UpdateRepo/UpdateRepoJob.php
@@ -153,7 +153,7 @@
 
                $summaryString = $this->summaryFormatter->formatSummary( 
$summary );
 
-               $editEntity = $this->editEntityFactory->newEditEntity( $user, 
$item->getId(), 0 );
+               $editEntity = $this->editEntityFactory->newEditEntity( $user, 
$item->getId(), 0, true );
                $status = $editEntity->attemptSave(
                        $item,
                        $summaryString,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1f4f8de5438f1028265b09982514c834e5d85f77
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to