From bd7256aedec54e5e3cac0d0ccf0e83a7dddf1361 Mon Sep 17 00:00:00 2001 From: "Mr. E23" Date: Mon, 5 Jan 2004 20:55:45 +0000 Subject: [PATCH] Moved linkscc SQL details into LinkCache for cleaner code. Also cleaned up LinkCache a bit. --- includes/Article.php | 18 ++++------- includes/LinkCache.php | 62 +++++++++++++++++++++++------------- includes/SpecialMovepage.php | 4 +-- includes/SpecialUndelete.php | 4 +-- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 5f8a57beff..da19b4f6ea 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ); } diff --git a/includes/LinkCache.php b/includes/LinkCache.php index 554a7ca543..ba58e2c9b9 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -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); } } ?> diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 0ea4a5d4f5..f72873983b 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -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}'"; diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index 549e30f1ff..7226c3c7dd 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -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. } -- 2.20.1