Experimental code for caching page links
authorMr. E23 <e23@users.mediawiki.org>
Sat, 8 Nov 2003 15:12:34 +0000 (15:12 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Sat, 8 Nov 2003 15:12:34 +0000 (15:12 +0000)
includes/Article.php
includes/LinkCache.php
includes/LinksUpdate.php

index 4c6d3b5..d7a8fd3 100644 (file)
@@ -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 );
index 99e1f2c..23f5182 100644 (file)
@@ -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 );
        }
 
index 98bc427..b87f2c4 100644 (file)
@@ -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;