Add page_latest to the LinkCache.
authorPlatonides <platonides@users.mediawiki.org>
Tue, 15 Jun 2010 12:14:54 +0000 (12:14 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Tue, 15 Jun 2010 12:14:54 +0000 (12:14 +0000)
includes/Article.php
includes/LinkBatch.php
includes/LinkCache.php
includes/Title.php
includes/WatchlistEditor.php
includes/filerepo/File.php
includes/parser/LinkHolderArray.php

index c28275e..3e87641 100644 (file)
@@ -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 );
 
index b8d90eb..7df39e2 100644 (file)
@@ -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__ );
index 8d9d80d..33ab299 100644 (file)
@@ -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;
index 29a4e70..1b812a8 100644 (file)
@@ -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;
                                }
                        }
index 72b12c2..638b47a 100644 (file)
@@ -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 );
                                        }
index 2bc7f06..4cf7d3a 100644 (file)
@@ -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;
                                }
                        }
index 37c1387..a615912 100644 (file)
@@ -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