From d35dbd9f50207aaad3989b66a1cc4b220184a06e Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Tue, 3 Feb 2009 04:57:28 +0000 Subject: [PATCH] Cache cite output by contents. That way, changes that don't affect Cite references won't cause a re-parsing of Cite, which is a big CPU hog on Wikimedia. --- Cite_body.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Cite_body.php b/Cite_body.php index 1c9104dbc..787de86a5 100644 --- a/Cite_body.php +++ b/Cite_body.php @@ -360,12 +360,28 @@ class Cite { $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' ); $suffix = wfMsgForContentNoTrans( 'cite_references_suffix' ); $content = implode( "\n", $ent ); - + + // Let's try to cache it. + $parserInput = $prefix . $content . $suffix; + global $wgMemc; + $cacheKey = wfMemcKey( 'citeref', md5($parserInput), $this->mParser->Title()->getArticleID() ); + wfProfileOut( __METHOD__ .'-entries' ); - wfProfileIn( __METHOD__ .'-parse' ); - // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar - $ret = rtrim( $this->parse( $prefix . $content . $suffix ), "\n" ); - wfProfileOut( __METHOD__ .'-parse' ); + + wfProfileIn( __METHOD__.'-cache-get' ); + $ret = $wgMemc->get( $cacheKey ); + wfProfileOut( __METHOD__.'-cache' ); + + if ( !$ret ) { + wfProfileIn( __METHOD__ .'-parse' ); + + // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar + $ret = rtrim( $this->parse( $parserInput ), "\n" ); + $wgMemc->set( $cacheKey, $ret, 86400 ); + + wfProfileOut( __METHOD__ .'-parse' ); + } + wfProfileOut( __METHOD__ ); //done, clean up so we can reuse the group