Moved linkscc SQL details into LinkCache for cleaner code. Also cleaned up LinkCache...
authorMr. E23 <e23@users.mediawiki.org>
Mon, 5 Jan 2004 20:55:45 +0000 (20:55 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Mon, 5 Jan 2004 20:55:45 +0000 (20:55 +0000)
includes/Article.php
includes/LinkCache.php
includes/SpecialMovepage.php
includes/SpecialUndelete.php

index 5f8a57b..da19b4f 100644 (file)
@@ -401,9 +401,7 @@ class Article {
 
                if ( $wgEnablePersistentLC ) {
                        // Purge related entries in links cache on new page, to heal broken links
-                       $ptitle = wfStrencode( $ttl );
-                       wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
-                               "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
+                       LinkCache::linksccClearBrokenLinksTo( $ttl );
                }
                
                $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
@@ -535,9 +533,8 @@ class Article {
                        global $wgEnablePersistentLC;
                        if ( $wgEnablePersistentLC ) {
                                // Purge link cache for this page
-                               $pageid=$this->getID();
-                               wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
-                       }                       
+                               LinkCache::linksccClearPage( $this->getID() );
+                       }
                }
 
                if( $wgDBtransactions ) {
@@ -873,9 +870,7 @@ class Article {
 
                        if ( $wgEnablePersistentLC ) {
                                // Purge related entries in links cache on delete,
-                               wfQuery("DELETE linkscc FROM linkscc,links ".
-                                       "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE);
-                               wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE);
+                               LinkCache::linksccClearLinksTo( $id );
                        }
 
                        $sql = "SELECT l_from FROM links WHERE l_to={$id}";
@@ -1004,10 +999,9 @@ class Article {
 
                global $wgEnablePersistentLC;
                if ( $wgEnablePersistentLC ) {
-                       wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
+                       LinkCache::linksccClearPage( $pid );
                }
-               
-                       
+                                       
                $wgOut->returnToMain( false );
        }
        
index 554a7ca..ba58e2c 100644 (file)
@@ -152,18 +152,11 @@ class LinkCache {
                $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
 
                if ( $wgEnablePersistentLC ) {
-                       $cc =& $this->getFromLinkscc( $dbkeyfrom );
-                       if( $cc != FALSE ){
-                               $this->mOldGoodLinks = $this->mGoodLinks = $cc->mGoodLinks;
-                               $this->mOldBadLinks = $this->mBadLinks = $cc->mBadLinks;
-                               $this->mPreFilled = true;
-                               wfProfileOut( $fname );
-                               wfDebug( "LinkCache::preFill - got from linkscc\n" );
+                       if( $this->fillFromLinkscc( $dbkeyfrom ) ){
                                return;
-                       } 
+                       }
                }
 
-
                $sql = "SELECT cur_id,cur_namespace,cur_title
                        FROM cur,links
                        WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
@@ -197,17 +190,8 @@ class LinkCache {
                $this->mPreFilled = true;
 
                if ( $wgEnablePersistentLC ) {
-                       // put fetched link data into cache
-                       if( $wgCompressedPersistentLC and function_exists( "gzcompress" ) ) {
-                               $ser = wfStrencode( gzcompress( serialize( $this ), 3 ));
-                       } else {
-                               $ser = wfStrencode( serialize( $this ) );
-                       }
-                       wfQuery("REPLACE INTO linkscc(lcc_pageid,lcc_title,lcc_cacheobj) VALUES({$id}, '{$dbkeyfrom}', '{$ser}')", 
-                               DB_WRITE);
-                               wfDebug( "$fname - saved to linkscc\n" );
+                       $this->saveToLinkscc( $id, $dbkeyfrom );
                }
-
                wfProfileOut( $fname );
        }
 
@@ -281,8 +265,7 @@ class LinkCache {
                $this->mImageLinks = array();
        }
 
-
-       function &getFromLinkscc( $dbkeyfrom ){
+       /* private */ function fillFromLinkscc( $dbkeyfrom ){ 
                $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'", 
                        DB_READ);
                $row = wfFetchObject( $res );
@@ -298,10 +281,45 @@ class LinkCache {
                }
                $cc = @unserialize( $cacheobj );
                if( isset( $cc->mClassVer ) and ($cc->mClassVer == $this->mClassVer ) ){
-                       return $cc;
+                       $this->mOldGoodLinks = $this->mGoodLinks = $cc->mGoodLinks;
+                       $this->mOldBadLinks = $this->mBadLinks = $cc->mBadLinks;
+                       $this->mPreFilled = true;
+                       return TRUE;
                } else {
                        return FALSE;
                }
+
+       }
+
+       /* private */ function saveToLinkscc( $pid, $dbkeyfrom ){
+               if( $wgCompressedPersistentLC and function_exists( "gzcompress" ) ) {
+                       $ser = wfStrencode( gzcompress( serialize( $this ), 3 ));
+               } else {
+                       $ser = wfStrencode( serialize( $this ) );
+               }
+               wfQuery("REPLACE INTO linkscc(lcc_pageid,lcc_title,lcc_cacheobj) " .
+                       "VALUES({$pid}, '{$dbkeyfrom}', '{$ser}')", DB_WRITE);
+       }
+
+       # $pid is a page id
+       /* static */ function linksccClearLinksTo( $pid ){
+               $pid = intval( $pid );
+               wfQuery("DELETE linkscc FROM linkscc,links ".
+                       "WHERE lcc_title=links.l_from AND l_to={$pid}", DB_WRITE);
+               wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
+       }
+
+       # $title is a prefixed db title, for example like Title->getPrefixedDBkey() returns.
+       /* static */ function linksccClearBrokenLinksTo( $title ){
+               $title = wfStrencode( $title );
+               wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
+                       "WHERE lcc_pageid=bl_from AND bl_to='{$title}'", DB_WRITE);
+       }
+
+       # $pid is a page id
+       /* static */ function linksccClearPage( $pid ){
+               $id = intval( $pid );
+               wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
        }
 }
 ?>
index 0ea4a5d..f728739 100644 (file)
@@ -391,9 +391,7 @@ class MovePageForm {
                global $wgEnablePersistentLC;
                if ( $wgEnablePersistentLC ) {
                        // Purge related entries in links cache on new page, to heal broken links
-                       $ptitle = wfStrencode( $this->nft );
-                       wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
-                               "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
+                       LinkCache::linksccClearBrokenLinksTo( $this->nft );
                }
 
                $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'";
index 549e30f..7226c3c 100644 (file)
@@ -182,9 +182,7 @@ function wfSpecialUndelete( $par )
                        global $wgEnablePersistentLC;
                        if ( $wgEnablePersistentLC ) {
                                // Purge related entries in links cache on undelete, to heal broken links
-                               $ptitle = wfStrencode( $to->getPrefixedDBkey() );
-                               wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
-                                       "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
+                               LinkCache::linksccClearBrokenLinksTo( $to->getPrefixedDBkey() );
                        }
                        #TODO: SearchUpdate, etc.
                }