From e6a33f0c8145127c8ca2de471ab5bed980eaf51e Mon Sep 17 00:00:00 2001 From: Alex Z Date: Fri, 10 Oct 2008 22:19:55 +0000 Subject: [PATCH] Adding file cache to the parser to improve rendering time on pages with several uses of the same image; designed with input from Brion and Tim. Cache size is limited to 1000. --- RELEASE-NOTES | 2 ++ includes/parser/Parser.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8fcba5c6e3..1907f1afb4 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 14c472f002..427e4ff630 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 ); -- 2.20.1