From 62539289ae9c49ea7a556f5b6309efacef299355 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 28 Oct 2005 11:05:32 +0000 Subject: [PATCH] * Avoid numerous redundant latest-revision lookups in history --- RELEASE-NOTES | 2 ++ includes/PageHistory.php | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2ae0312d36..65a4d88ace 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -188,6 +188,8 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 3762) Define missing Special:Import UI messages * (bug 3771) Handle internal functions in backtrace in wfAbruptExit() * (bug 3649) Remove obsolete, broken moveCustomMessages script +* (bug 3291) 'last' diff link for last history line when not at end +* Avoid numerous redundant latest-revision lookups in history === Caveats === diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 8280d26ffa..56c2737af1 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -28,6 +28,7 @@ class PageHistory { var $lastdate; var $linesonpage; var $mNotificationTimestamp; + var $mLatestId = null; /** * Construct a new PageHistory. @@ -302,8 +303,17 @@ class PageHistory { function lastLink( $row, $next, $counter ) { global $wgUser; $last = htmlspecialchars( wfMsg( 'last' ) ); - if( is_null( $next ) - || ( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) ) { + if( is_null( $next ) ) { + if( $row->rev_timestamp == $this->getEarliestOffset() ) { + return $last; + } else { + // Cut off by paging; there are more behind us... + return $this->mSkin->makeKnownLinkObj( + $this->mTitle, + $last, + "diff={$row->rev_id}&oldid=prev" ); + } + } elseif( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) { return $last; } else { return $this->mSkin->makeKnownLinkObj( @@ -384,13 +394,16 @@ class PageHistory { } /** @todo document */ - function getLatestID( $id = null ) { - if ( $id === null) $id = $this->mTitle->getArticleID(); - $db =& wfGetDB(DB_SLAVE); - return $db->selectField( 'revision', - "max(rev_id)", - array( 'rev_page' => $id ), - 'PageHistory::getLatestID' ); + function getLatestId() { + if( is_null( $this->mLatestId ) ) { + $id = $this->mTitle->getArticleID(); + $db =& wfGetDB(DB_SLAVE); + $this->mLatestId = $db->selectField( 'revision', + "max(rev_id)", + array( 'rev_page' => $id ), + 'PageHistory::getLatestID' ); + } + return $this->mLatestId; } /** @todo document */ -- 2.20.1