Adding file cache to the parser to improve rendering time on pages with several uses...
authorAlex Z <mrzman@users.mediawiki.org>
Fri, 10 Oct 2008 22:19:55 +0000 (22:19 +0000)
committerAlex Z <mrzman@users.mediawiki.org>
Fri, 10 Oct 2008 22:19:55 +0000 (22:19 +0000)
RELEASE-NOTES
includes/parser/Parser.php

index 8fcba5c..1907f1a 100644 (file)
@@ -165,6 +165,8 @@ The following extensions are migrated into MediaWiki 1.14:
 * Added the ability to display user edit counts in Special:ListUsers. Off by 
   default, enabled with $wgEdititis = true (named after the medical condition 
   marked by unhealthy obsession with edit counts).
+* Added a file cache to the parser to improve page rendering time on pages with
+  several uses of the same image.
 
 === Bug fixes in 1.14 ===
 
index 14c472f..427e4ff 100644 (file)
@@ -103,6 +103,7 @@ class Parser
        var $mTplExpandCache; // empty-frame expansion cache
        var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores;
        var $mExpensiveFunctionCount; // number of expensive parser function calls
+       var $mFileCache;
 
        # Temporary
        # These are variables reset at least once per parse regardless of $clearState
@@ -229,6 +230,7 @@ class Parser
                $this->mHeadings = array();
                $this->mDoubleUnderscores = array();
                $this->mExpensiveFunctionCount = 0;
+               $this->mFileCache = array();
 
                # Fix cloning
                if ( isset( $this->mPreprocessor ) && $this->mPreprocessor->parser !== $this ) {
@@ -4292,8 +4294,18 @@ class Parser
                        return $sk->link( $title );
                }
 
+               # Get the file
+               $imagename = $title->getDBkey();
+               if ( isset( $this->mFileCache[$imagename][$time] ) ) {
+                       $file = $this->mFileCache[$imagename][$time];
+               } else {
+                       $file = wfFindFile( $title, $time );
+                       if ( !(count( $this->mFileCache ) <= 1000) ) {
+                               $this->mFileCache = array();
+                       }
+                       $this->mFileCache[$imagename][$time] = $file;
+               }
                # Get parameter map
-               $file = wfFindFile( $title, $time );
                $handler = $file ? $file->getHandler() : false;
 
                list( $paramMap, $mwArray ) = $this->getImageParams( $handler );