From 84460b0862cbbff31d55cefe7e5043686351d507 Mon Sep 17 00:00:00 2001 From: Elliott Eggleston Date: Fri, 14 Dec 2018 15:06:53 -0500 Subject: [PATCH] Option to load restrictions from DB_MASTER Adds a $readLatest parameter to Title::loadRestrictions that skips the replica DBs and goes straight to the master DB to get the latest. TODO: should I add $readLatest to all the getRestrictions* functions? Bug: T210983 Change-Id: I834de033fb79870de7d081701693663fb6ee93d3 --- includes/Title.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 55c5cd90f1..155bee10ab 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3276,9 +3276,13 @@ class Title implements LinkTarget { * indicating who can move or edit the page from the page table, (pre 1.10) rows. * Edit and move sections are separated by a colon * Example: "edit=autoconfirmed,sysop:move=sysop" + * @param bool $readLatest When true, skip replicas and read from the master DB. */ - public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { - $dbr = wfGetDB( DB_REPLICA ); + public function loadRestrictionsFromRows( + $rows, $oldFashionedRestrictions = null, $readLatest = false + ) { + $whichDb = $readLatest ? DB_MASTER : DB_REPLICA; + $dbr = wfGetDB( $whichDb ); $restrictionTypes = $this->getRestrictionTypes(); @@ -3348,9 +3352,10 @@ class Title implements LinkTarget { * indicating who can move or edit the page from the page table, (pre 1.10) rows. * Edit and move sections are separated by a colon * Example: "edit=autoconfirmed,sysop:move=sysop" + * @param bool $readLatest When true, skip replicas and read from the master DB. */ - public function loadRestrictions( $oldFashionedRestrictions = null ) { - if ( $this->mRestrictionsLoaded ) { + public function loadRestrictions( $oldFashionedRestrictions = null, $readLatest = false ) { + if ( $this->mRestrictionsLoaded && !$readLatest ) { return; } @@ -3360,10 +3365,11 @@ class Title implements LinkTarget { $fname = __METHOD__; $rows = $cache->getWithSetCallback( // Page protections always leave a new null revision - $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ), + $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID(), $readLatest ), $cache::TTL_DAY, - function ( $curValue, &$ttl, array &$setOpts ) use ( $fname ) { - $dbr = wfGetDB( DB_REPLICA ); + function ( $curValue, &$ttl, array &$setOpts ) use ( $fname, $readLatest ) { + $whichDb = $readLatest ? DB_MASTER : DB_REPLICA; + $dbr = wfGetDB( $whichDb ); $setOpts += Database::getCacheSetOptions( $dbr ); @@ -3378,7 +3384,7 @@ class Title implements LinkTarget { } ); - $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions ); + $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions, $readLatest ); } else { $title_protection = $this->getTitleProtectionInternal(); -- 2.20.1