* (bug 1132) Fix concatenation of link lists in refreshLinks
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 15 Jan 2005 07:08:37 +0000 (07:08 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 15 Jan 2005 07:08:37 +0000 (07:08 +0000)
* (bug 1101) Fix memory leak in refreshLinks

includes/Title.php
maintenance/refreshLinks.inc

index bdc57ca..167d406 100644 (file)
@@ -11,6 +11,13 @@ require_once( 'normal/UtfNormal.php' );
 $wgTitleInterwikiCache = array();
 define ( 'GAID_FOR_UPDATE', 1 );
 
+# Title::newFromTitle maintains a cache to avoid
+# expensive re-normalization of commonly used titles.
+# On a batch operation this can become a memory leak
+# if not bounded. After hitting this many titles,
+# reset the cache.
+define( 'MW_TITLECACHE_MAX', 1000 );
+
 /**
  * Title class
  * - Represents a title, which may contain an interwiki designation or namespace
@@ -130,6 +137,10 @@ class Title {
 
                if( $t->secureAndSplit() ) {
                        if( $defaultNamespace == 0 ) {
+                               if( count( $titleCache ) >= MW_TITLECACHE_MAX ) {
+                                       # Avoid memory leaks on mass operations...
+                                       $titleCache = array();
+                               }
                                $titleCache[$text] =& $t;
                        }
                        wfProfileOut( $fname );
index 60f2981..743293f 100644 (file)
@@ -41,6 +41,16 @@ function refreshLinks( $start ) {
                $text = $wgArticle->getContent( true );
                $wgLinkCache = new LinkCache;
                $wgLinkCache->forUpdate( true );
+               
+               global $wgLinkHolders;
+               $wgLinkHolders = array(
+                       'namespaces' => array(),
+                       'dbkeys' => array(),
+                       'queries' => array(),
+                       'texts' => array(),
+                       'titles' => array()
+               );
+
 
                # Parse the text and replace links with placeholders
                $wgOut->addWikiText( $text );