From: Platonides Date: Tue, 15 Jun 2010 12:14:54 +0000 (+0000) Subject: Add page_latest to the LinkCache. X-Git-Tag: 1.31.0-rc.0~36505 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=b81bae03d0d1b9cd38255e3460752fa9a112c302;p=lhc%2Fweb%2Fwiklou.git Add page_latest to the LinkCache. --- diff --git a/includes/Article.php b/includes/Article.php index c28275e97f..3e876410a7 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -458,7 +458,7 @@ class Article { $lc = LinkCache::singleton(); if ( $data ) { - $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect ); + $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest ); $this->mTitle->mArticleID = intval( $data->page_id ); diff --git a/includes/LinkBatch.php b/includes/LinkBatch.php index b8d90eb57e..7df39e2496 100644 --- a/includes/LinkBatch.php +++ b/includes/LinkBatch.php @@ -97,7 +97,7 @@ class LinkBatch { $remaining = $this->data; while ( $row = $res->fetchObject() ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); - $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect ); + $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest ); $ids[$title->getPrefixedDBkey()] = $row->page_id; unset( $remaining[$row->page_namespace][$row->page_title] ); } @@ -131,7 +131,7 @@ class LinkBatch { wfProfileOut( __METHOD__ ); return false; } - $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect FROM $page WHERE $set"; + $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest FROM $page WHERE $set"; // Do query $res = $dbr->query( $sql, __METHOD__ ); diff --git a/includes/LinkCache.php b/includes/LinkCache.php index 8d9d80d885..33ab2992d5 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -72,12 +72,13 @@ class LinkCache { * @param $len Integer * @param $redir Integer */ - public function addGoodLinkObj( $id, $title, $len = -1, $redir = null ) { + public function addGoodLinkObj( $id, $title, $len = -1, $redir = null, $revision = false ) { $dbkey = $title->getPrefixedDbKey(); $this->mGoodLinks[$dbkey] = intval( $id ); $this->mGoodLinkFields[$dbkey] = array( 'length' => intval( $len ), - 'redirect' => intval( $redir ) ); + 'redirect' => intval( $redir ), + 'revision' => intval( $revision ) ); } public function addBadLinkObj( $title ) { @@ -164,7 +165,7 @@ class LinkCache { } $s = $db->selectRow( 'page', - array( 'page_id', 'page_len', 'page_is_redirect' ), + array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ), array( 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ), __METHOD__, $options ); # Set fields... @@ -172,15 +173,17 @@ class LinkCache { $id = intval( $s->page_id ); $len = intval( $s->page_len ); $redirect = intval( $s->page_is_redirect ); + $revision = intval( $s->page_latest ); } else { $len = -1; $redirect = 0; + $revision = 0; } if ( $id == 0 ) { $this->addBadLinkObj( $nt ); } else { - $this->addGoodLinkObj( $id, $nt, $len, $redirect ); + $this->addGoodLinkObj( $id, $nt, $len, $redirect, $revision ); } wfProfileOut( __METHOD__ ); return $id; diff --git a/includes/Title.php b/includes/Title.php index 29a4e70fd8..1b812a84ce 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2326,15 +2326,18 @@ class Title { * What is the page_latest field for this page? * * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update - * @return \type{\int} or false if the page doesn't exist + * @return \type{\int} or 0 if the page doesn't exist */ public function getLatestRevID( $flags = 0 ) { if ( $this->mLatestID !== false ) return $this->mLatestID; + # Calling getArticleID() loads the field from cache as needed + if ( !$this->getArticleID( $flags ) ) { + return $this->mLatestID = 0; + } + $linkCache = LinkCache::singleton(); + $this->mLatestID = intval( $linkCache->getGoodLinkFieldObj( $this, 'revision' ) ); - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); - $this->mLatestID = (int)$db->selectField( - 'page', 'page_latest', $this->pageCond(), __METHOD__ ); return $this->mLatestID; } @@ -2715,7 +2718,7 @@ class Title { } $res = $db->select( array( 'page', $table ), - array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ), + array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ), array( "{$prefix}_from=page_id", "{$prefix}_namespace" => $this->getNamespace(), @@ -2727,7 +2730,7 @@ class Title { if ( $db->numRows( $res ) ) { foreach ( $res as $row ) { if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) { - $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect ); + $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest ); $retVal[] = $titleObj; } } diff --git a/includes/WatchlistEditor.php b/includes/WatchlistEditor.php index 72b12c2d9d..638b47a4b7 100644 --- a/includes/WatchlistEditor.php +++ b/includes/WatchlistEditor.php @@ -205,7 +205,7 @@ class WatchlistEditor { $dbr = wfGetDB( DB_MASTER ); $uid = intval( $user->getId() ); list( $watchlist, $page ) = $dbr->tableNamesN( 'watchlist', 'page' ); - $sql = "SELECT wl_namespace, wl_title, page_id, page_len, page_is_redirect + $sql = "SELECT wl_namespace, wl_title, page_id, page_len, page_is_redirect, page_latest FROM {$watchlist} LEFT JOIN {$page} ON ( wl_namespace = page_namespace AND wl_title = page_title ) WHERE wl_user = {$uid}"; $res = $dbr->query( $sql, __METHOD__ ); @@ -216,7 +216,7 @@ class WatchlistEditor { if( $title instanceof Title ) { // Update the link cache while we're at it if( $row->page_id ) { - $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect ); + $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest ); } else { $cache->addBadLinkObj( $title ); } diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 2bc7f06387..4cf7d3a2a4 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -879,7 +879,7 @@ abstract class File { $encName = $db->addQuotes( $this->getName() ); $res = $db->select( array( 'page', 'imagelinks'), - array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ), + array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ), array( 'page_id' => 'il_from', 'il_to' => $encName ), __METHOD__, $options ); @@ -888,7 +888,7 @@ abstract class File { if ( $db->numRows( $res ) ) { while ( $row = $db->fetchObject( $res ) ) { if ( $titleObj = Title::newFromRow( $row ) ) { - $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect ); + $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest ); $retVal[] = $titleObj; } } diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 37c1387c5a..a615912742 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -174,7 +174,7 @@ class LinkHolderArray { # Not in the link cache, add it to the query if ( !isset( $current ) ) { $current = $ns; - $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len"; + $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len, page_latest"; $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN("; } elseif ( $current != $ns ) { $current = $ns; @@ -197,7 +197,7 @@ class LinkHolderArray { while ( $s = $dbr->fetchObject($res) ) { $title = Title::makeTitle( $s->page_namespace, $s->page_title ); $pdbk = $title->getPrefixedDBkey(); - $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect ); + $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect, $s->page_latest ); $output->addLink( $title, $s->page_id ); # FIXME: convoluted data flow # The redirect status and length is passed to getLinkColour via the LinkCache