Aaron Schulz has uploaded a new change for review.

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

Change subject: Avoid excess master queries in getTimestampFromId
......................................................................

Avoid excess master queries in getTimestampFromId

Bug: T92357
Change-Id: Id5cf7a5620daeee12abfa778f9be19435f3e5e84
---
M includes/Revision.php
1 file changed, 8 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/37/195837/1

diff --git a/includes/Revision.php b/includes/Revision.php
index d535028..cc00f9f 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -1684,23 +1684,21 @@
         *
         * @param Title $title
         * @param int $id
-        * @return string
+        * @return string|bool False if not found
         */
-       static function getTimestampFromId( $title, $id ) {
-               $dbr = wfGetDB( DB_SLAVE );
+       static function getTimestampFromId( $title, $id, $flags = 0 ) {
+               $db = ( $flags & self::READ_LATEST )
+                       ? wfGetDB( DB_MASTER )
+                       : wfGetDB( DB_SLAVE );
                // Casting fix for databases that can't take '' for rev_id
                if ( $id == '' ) {
                        $id = 0;
                }
                $conds = array( 'rev_id' => $id );
                $conds['rev_page'] = $title->getArticleID();
-               $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', 
$conds, __METHOD__ );
-               if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
-                       # Not in slave, try master
-                       $dbw = wfGetDB( DB_MASTER );
-                       $timestamp = $dbw->selectField( 'revision', 
'rev_timestamp', $conds, __METHOD__ );
-               }
-               return wfTimestamp( TS_MW, $timestamp );
+               $timestamp = $db->selectField( 'revision', 'rev_timestamp', 
$conds, __METHOD__ );
+
+               return ( $timestamp !== false ) ? wfTimestamp( TS_MW, 
$timestamp ) : false;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5cf7a5620daeee12abfa778f9be19435f3e5e84
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

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

Reply via email to