From: Mr. E23 Date: Sat, 8 Nov 2003 15:12:34 +0000 (+0000) Subject: Experimental code for caching page links X-Git-Tag: 1.1.0~187 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=665c30813eddfc959021b5c71772302611f10121;p=lhc%2Fweb%2Fwiklou.git Experimental code for caching page links --- diff --git a/includes/Article.php b/includes/Article.php index 4c6d3b5c12..d7a8fd3d76 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -338,6 +338,11 @@ class Article { $newid = wfInsertId(); $this->mTitle->resetArticleID( $newid ); + // 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); + $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," . "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," . "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" . @@ -454,6 +459,13 @@ class Article { $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " . "WHERE rc_cur_id=" . $this->getID(); wfQuery( $sql, DB_WRITE, $fname ); + + // Purge related entries in link cache when a page change + // (probably just affects anything when article changes stub state) + $pageid=$this->getID(); + wfQuery("DELETE linkscc FROM linkscc,links ". + "WHERE lcc_title=links.l_from AND l_to={$pageid}", DB_WRITE); + } if( $wgDBtransactions ) { $sql = "COMMIT"; @@ -830,6 +842,12 @@ class Article { # Finally, clean up the link tables if ( 0 != $id ) { + + // 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); + $t = wfStrencode( $title->getPrefixedDBkey() ); $sql = "SELECT l_from FROM links WHERE l_to={$id}"; $res = wfQuery( $sql, DB_READ, $fname ); diff --git a/includes/LinkCache.php b/includes/LinkCache.php index 99e1f2c691..23f5182c02 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -141,6 +141,22 @@ class LinkCache { wfProfileIn( $fname ); # Note -- $fromtitle is a Title *object* $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() ); + + + $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'", + DB_READ); + $row = wfFetchObject( $res ); + if( $row != FALSE){ + $cacheobj = gzuncompress( $row->lcc_cacheobj ); + $cc = unserialize( $cacheobj ); + $this->mGoodLinks = $cc->mGoodLinks; + $this->mBadLinks = $cc->mBadLinks; + $this->mPreFilled = true; + wfProfileOut( $fname ); + return; + } + + $sql = "SELECT cur_id,cur_namespace,cur_title FROM cur,links WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'"; @@ -166,7 +182,12 @@ class LinkCache { $this->mOldBadLinks = $this->mBadLinks; $this->mOldGoodLinks = $this->mGoodLinks; $this->mPreFilled = true; - + + // put fetched link data into cache + $serCachegz = wfStrencode( gzcompress( serialize( $this ), 3) ); + wfQuery("REPLACE INTO linkscc VALUES({$id}, '{$dbkeyfrom}', '{$serCachegz}')", + DB_WRITE); + wfProfileOut( $fname ); } diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 98bc427182..b87f2c46e1 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -12,6 +12,7 @@ class LinksUpdate { $this->mTitleEnc = wfStrencode( $title ); } + function doUpdate() { global $wgUseBetterLinksUpdate, $wgLinkCache, $wgDBtransactions; @@ -19,6 +20,9 @@ class LinksUpdate { /* Update link tables with outgoing links from an updated article */ /* Relies on the 'link cache' to be filled out */ + // Make sure links cache is regenerated on next load + wfQuery("DELETE FROM linkscc WHERE lcc_title = '{$safeTitle}'", DB_WRITE); + if ( !$wgUseBetterLinksUpdate ) { $this->doDumbUpdate(); return;