jenkins-bot has submitted this change and it was merged.
Change subject: Avoid excess master queries in getTimestampFromId
......................................................................
Avoid excess master queries in getTimestampFromId
Bug: T92357
Change-Id: Id5cf7a5620daeee12abfa778f9be19435f3e5e84
---
M includes/Revision.php
M includes/api/ApiSetNotificationTimestamp.php
2 files changed, 12 insertions(+), 12 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
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;
}
/**
diff --git a/includes/api/ApiSetNotificationTimestamp.php
b/includes/api/ApiSetNotificationTimestamp.php
index 5d37e20..dec64cc 100644
--- a/includes/api/ApiSetNotificationTimestamp.php
+++ b/includes/api/ApiSetNotificationTimestamp.php
@@ -73,7 +73,8 @@
}
$title = reset( $pageSet->getGoodTitles() );
if ( $title ) {
- $timestamp = Revision::getTimestampFromId(
$title, $params['torevid'] );
+ $timestamp = Revision::getTimestampFromId(
+ $title, $params['torevid'],
Revision::READ_LATEST );
if ( $timestamp ) {
$timestamp = $dbw->timestamp(
$timestamp );
} else {
@@ -86,7 +87,8 @@
}
$title = reset( $pageSet->getGoodTitles() );
if ( $title ) {
- $revid = $title->getNextRevisionID(
$params['newerthanrevid'] );
+ $revid = $title->getNextRevisionID(
+ $params['newerthanrevid'],
Title::GAID_FOR_UPDATE );
if ( $revid ) {
$timestamp = $dbw->timestamp(
Revision::getTimestampFromId( $title, $revid ) );
} else {
--
To view, visit https://gerrit.wikimedia.org/r/195837
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id5cf7a5620daeee12abfa778f9be19435f3e5e84
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits