X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=blobdiff_plain;f=includes%2FRevision.php;h=8f36e88fbea06079fa13b0d3bbcf482e2b3966f3;hb=07d0b2368516446c60593f2c021e9c2c7c032ce3;hp=af4fef51dedfc64f9ed247b6d221731abe5b580e;hpb=073fd06f15fe12298c4c453f2429be20c316c4e4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Revision.php b/includes/Revision.php index af4fef51de..8f36e88fbe 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -94,10 +94,52 @@ class Revision implements IDBAccessObject { * * @param int $id * @param int $flags (optional) - * @param Title $title (optional) + * @param Title $title (optional) If known you can pass the Title in here. + * Passing no Title may result in another DB query if there are recent writes. * @return Revision|null */ public static function newFromId( $id, $flags = 0, Title $title = null ) { + /** + * MCR RevisionStore Compat + * + * If the title is not passed in as a param (already known) then select it here. + * + * Do the selection with MASTER if $flags includes READ_LATEST or recent changes + * have happened on our load balancer. + * + * If we select the title here and pass it down it will results in fewer queries + * further down the stack. + */ + if ( !$title ) { + if ( + $flags & self::READ_LATEST || + wfGetLB()->hasOrMadeRecentMasterChanges() + ) { + $dbr = wfGetDB( DB_MASTER ); + } else { + $dbr = wfGetDB( DB_REPLICA ); + } + $row = $dbr->selectRow( + [ 'revision', 'page' ], + [ + 'page_namespace', + 'page_title', + 'page_id', + 'page_latest', + 'page_is_redirect', + 'page_len', + ], + [ 'rev_id' => $id ], + __METHOD__, + [], + [ 'page' => [ 'JOIN', 'page_id=rev_page' ] ] + ); + if ( $row ) { + $title = Title::newFromRow( $row ); + } + wfGetLB()->reuseConnection( $dbr ); + } + $rec = self::getRevisionStore()->getRevisionById( $id, $flags, $title ); return $rec === null ? null : new Revision( $rec, $flags, $title ); }