Fix move page / linkcache / memcached problem
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 4 Nov 2003 08:59:28 +0000 (08:59 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 4 Nov 2003 08:59:28 +0000 (08:59 +0000)
includes/LinkCache.php
includes/SpecialMovepage.php

index 25b84ac..99e1f2c 100644 (file)
@@ -12,6 +12,11 @@ class LinkCache {
        /* private */ var $mImageLinks; 
        /* private */ var $mPreFilled, $mOldGoodLinks, $mOldBadLinks;
        
+       /* private */ function getKey( $title ) {
+               global $wgDBname;
+               return "$wgDBname:lc:title:$title";
+       }
+       
        function LinkCache()
        {
                $this->mActive = true;
@@ -56,14 +61,23 @@ class LinkCache {
                if ( $this->mActive ) { $this->mImageLinks[$title] = 1; }
        }
 
+       function addImageLinkObj( $nt )
+       {
+               if ( $this->mActive ) { $this->mImageLinks[$nt->getDBkey()] = 1; }
+       }
+
        function clearBadLink( $title )
        {
                $index = array_search( $title, $this->mBadLinks );
                if ( isset( $index ) ) {
                        unset( $this->mBadLinks[$index] );
                }
-               global $wgMemc, $wgDBname;
-               $wgMemc->delete( "$wgDBname:lc:title:$title" );
+               $this->clearLink( $title );
+       }
+       
+       function clearLink( $title ) {
+               global $wgMemc;
+               $wgMemc->delete( $this->getKey( $title ) );
        }
 
        function suspend() { $this->mActive = false; }
@@ -74,31 +88,37 @@ class LinkCache {
 
        function addLink( $title )
        {
-               return $this->addLinkObj( Title::newFromDBkey( $title ) );
+               $nt = Title::newFromDBkey( $title );
+               if( $nt ) {
+                       return $this->addLinkObj( $nt );
+               } else {
+                       return 0;
+               }
        }
        
        function addLinkObj( &$nt )
        {
-               $title = $nt->getDBkey();
+               $title = $nt->getPrefixedDBkey();
                if ( $this->isBadLink( $title ) ) { return 0; }
                $id = $this->getGoodLinkID( $title );
                if ( 0 != $id ) { return $id; }
 
-               global $wgMemc, $wgDBname;
-               $fname = "LinkCache::addLink-checkdatabase";
+               global $wgMemc;
+               $fname = "LinkCache::addLinkObj";
                wfProfileIn( $fname );
 
                $ns = $nt->getNamespace();
+               $t = $nt->getDBkey();
 
                if ( "" == $title ) { 
                        wfProfileOut( $fname );
                        return 0; 
                }
 
-               $id = $wgMemc->get( $key = "$wgDBname:lc:title:$title" );
+               $id = $wgMemc->get( $key = $this->getKey( $title ) );
                if( $id === FALSE ) {
-                       $sql = "SELECT HIGH_PRIORITY cur_id FROM cur WHERE cur_namespace=" .
-                         "{$ns} AND cur_title='" . wfStrencode( $title ) . "'";
+                       $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
+                         "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
                        $res = wfQuery( $sql, DB_READ, "LinkCache::addLink" );
 
                        if ( 0 == wfNumRows( $res ) ) {
@@ -121,10 +141,10 @@ class LinkCache {
                wfProfileIn( $fname );
                # Note -- $fromtitle is a Title *object*
                $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
-               $sql = "SELECT HIGH_PRIORITY cur_id,cur_namespace,cur_title
+               $sql = "SELECT cur_id,cur_namespace,cur_title
                        FROM cur,links
                        WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
-               $res = wfQuery( $sql, DB_READ, "LinkCache::preFill" );
+               $res = wfQuery( $sql, DB_READ, $fname );
                while( $s = wfFetchObject( $res ) ) {
                        $this->addGoodLink( $s->cur_id,
                                Title::makeName( $s->cur_namespace, $s->cur_title )
@@ -135,7 +155,7 @@ class LinkCache {
                $id = $fromtitle->getArticleID();
                $this->resume();
                
-               $sql = "SELECT HIGH_PRIORITY bl_to
+               $sql = "SELECT bl_to
                        FROM brokenlinks
                        WHERE bl_from='{$id}'";
                $res = wfQuery( $sql, DB_READ, "LinkCache::preFill" );
index 3b77ac3..694b3a9 100644 (file)
@@ -261,7 +261,7 @@ class MovePageForm {
 
        function moveOverExistingRedirect()
        {
-               global $wgUser;
+               global $wgUser, $wgLinkCache;
                $fname = "MovePageForm::moveOverExistingRedirect";
                $mt = wfMsg( "movedto" );
 
@@ -270,6 +270,7 @@ class MovePageForm {
                  "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
                  "WHERE cur_id={$this->oldid}";
                wfQuery( $sql, DB_WRITE, $fname );
+               $wgLinkCache->clearLink( $this->nft );
 
                $sql = "UPDATE cur SET cur_touched='{$now}'," .
                  "cur_namespace={$this->ons},cur_title='{$this->odt}'," .
@@ -279,6 +280,7 @@ class MovePageForm {
                  "cur_user_text='" . wfStrencode( $wgUser->getName() ) . "'," .
                  "cur_is_redirect=1,cur_is_new=0 WHERE cur_id={$this->newid}";
                wfQuery( $sql, DB_WRITE, $fname );
+               $wgLinkCache->clearLink( $this->oft );
 
                $sql = "UPDATE old SET " .
                  "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
@@ -332,7 +334,7 @@ class MovePageForm {
 
        function moveToNewTitle()
        {
-               global $wgUser;
+               global $wgUser, $wgLinkCache;
                $fname = "MovePageForm::moveToNewTitle";
                $mt = wfMsg( "movedto" );
 
@@ -342,6 +344,7 @@ class MovePageForm {
                  "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
                  "WHERE cur_id={$this->oldid}";
                wfQuery( $sql, DB_WRITE, $fname );
+               $wgLinkCache->clearLink( $this->nft );
 
                $common = "{$this->ons},'{$this->odt}'," .
                  "'{$mt} \\\"{$this->nft}\\\"','" .
@@ -353,6 +356,7 @@ class MovePageForm {
                  "VALUES ({$common},'{$won}','{$now}','#REDIRECT [[{$this->nft}]]\n',1,1)";
                wfQuery( $sql, DB_WRITE, $fname );
                $this->newid = wfInsertId();
+               $wgLinkCache->clearLink( $this->oft );
 
                $sql = "UPDATE old SET " .
                  "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .