From: Brion Vibber Date: Sat, 27 Nov 2004 12:21:16 +0000 (+0000) Subject: Light optimization on Skin::makeLinkObj(). Shaves about 40ms off of [[List of Royal... X-Git-Tag: 1.5.0alpha1~1219 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=641c9023493f5c62303cface1c2ebc8c57e0f2f2;p=lhc%2Fweb%2Fwiklou.git Light optimization on Skin::makeLinkObj(). Shaves about 40ms off of [[List of Royal Navy ship names]] on my test rig (over 2500 links!) --- diff --git a/includes/Skin.php b/includes/Skin.php index 118f90cebb..7c067730ad 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1322,13 +1322,17 @@ class Skin { function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) { global $wgOut, $wgUser, $wgLinkHolders; $fname = 'Skin::makeLinkObj'; + wfProfileIn( $fname ); # Fail gracefully if ( ! isset($nt) ) { # wfDebugDieBacktrace(); + wfProfileOut( $fname ); return "{$prefix}{$text}{$trail}"; } + $ns = $nt->getNamespace(); + $dbkey = $nt->getDBkey(); if ( $nt->isExternal() ) { $u = $nt->getFullURL(); $link = $nt->getPrefixedURL(); @@ -1348,60 +1352,69 @@ class Skin { $t = "{$text}{$inside}"; $nr = array_push($wgInterwikiLinkHolders, $t); $retVal = '{$trail}"; - } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) { + } elseif ( 0 == $ns && "" == $dbkey ) { + # A self-link with a fragment; skip existence check. $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); - } elseif ( ( -1 == $nt->getNamespace() ) || - ( NS_IMAGE == $nt->getNamespace() ) ) { + } elseif ( ( NS_SPECIAL == $ns ) || ( NS_IMAGE == $ns ) ) { + # These are always shown as existing, currently. + # Special pages don't exist in the database; images may + # occasionally be present when there is no description + # page per se, so we always shown them. $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); - } else { - if ( $this->postParseLinkColour() ) { - $inside = ''; - if ( '' != $trail ) { - if ( preg_match( $this->linktrail, $trail, $m ) ) { - $inside = $m[1]; - $trail = $m[2]; - } + } elseif ( $this->postParseLinkColour ) { + wfProfileIn( $fname.'-postparse' ); + # Insert a placeholder, and we'll work out the existence checks + # in a big lump later. + $inside = ''; + if ( '' != $trail ) { + if ( preg_match( $this->linktrail, $trail, $m ) ) { + $inside = $m[1]; + $trail = $m[2]; } + } - # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders() - $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() ); - $wgLinkHolders['dbkeys'][] = $nt->getDBkey(); - $wgLinkHolders['queries'][] = $query; - $wgLinkHolders['texts'][] = $prefix.$text.$inside; - $wgLinkHolders['titles'][] = $nt; + # These get picked up by Parser::replaceLinkHolders() + $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() ); + $wgLinkHolders['dbkeys'][] = $dbkey; + $wgLinkHolders['queries'][] = $query; + $wgLinkHolders['texts'][] = $prefix.$text.$inside; + $wgLinkHolders['titles'][] =& $nt; - $retVal = '{$trail}"; + $retVal = '{$trail}"; + wfProfileOut( $fname.'-postparse' ); + } else { + wfProfileIn( $fname.'-immediate' ); + # Work out link colour immediately + $aid = $nt->getArticleID() ; + if ( 0 == $aid ) { + $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); } else { - # Work out link colour immediately - $aid = $nt->getArticleID() ; - if ( 0 == $aid ) { - $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); - } else { - $threshold = $wgUser->getOption('stubthreshold') ; - if ( $threshold > 0 ) { - $dbr =& wfGetDB( DB_SLAVE ); - $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace', - 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ; - if ( $s !== false ) { - $size = $s->x; - if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) { - $size = $threshold*2 ; # Really big - } - $dbr->freeResult( $res ); - } else { + $threshold = $wgUser->getOption('stubthreshold') ; + if ( $threshold > 0 ) { + $dbr =& wfGetDB( DB_SLAVE ); + $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace', + 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ; + if ( $s !== false ) { + $size = $s->x; + if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) { $size = $threshold*2 ; # Really big } + $dbr->freeResult( $res ); } else { - $size = 1 ; - } - if ( $size < $threshold ) { - $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); - } else { - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); + $size = $threshold*2 ; # Really big } + } else { + $size = 1 ; + } + if ( $size < $threshold ) { + $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); + } else { + $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } } + wfProfileOut( $fname.'-immediate' ); } + wfProfileOut( $fname ); return $retVal; }