* Add caching to the AJAX search
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 14 Jan 2008 18:44:29 +0000 (18:44 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 14 Jan 2008 18:44:29 +0000 (18:44 +0000)
RELEASE-NOTES
includes/AjaxFunctions.php

index 1657d6b..6291317 100644 (file)
@@ -131,7 +131,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   edit, via the parameter 'bot'. (Default: '1')
 * (bug 12536) User should be able to get MediaWiki version from any page
 * (bug 12622) A JavaScript constant to declare whether api.php is available
+* Add caching to the AJAX search
+
 
 === Bug fixes in 1.12 ===
 
index b004cfc..d630461 100644 (file)
@@ -73,8 +73,10 @@ function code2utf($num){
    return '';
 }
 
+define( 'AJAX_SEARCH_VERSION', 1 );    //AJAX search cache version
+
 function wfSajaxSearch( $term ) {
-       global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks;
+       global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks, $wgMemc;
        $limit = 16;
        $sk = $wgUser->getSkin();
 
@@ -84,6 +86,14 @@ function wfSajaxSearch( $term ) {
                $term = $wgContLang->ucfirst( $term ); 
        $term_title = Title::newFromText( $term );
 
+       $memckey = wfMemcKey( 'ajaxsearch', md5( $term_title->getFullText() ) );
+       $cached = $wgMemc->get($memckey);
+       if( is_array( $cached ) && $cached['version'] == AJAX_SEARCH_VERSION ) {
+               $response = new AjaxResponse( $cached['html'] );
+               $response->setCacheDuration( 30*60 );
+               return $response;
+       }
+
        $r = $more = '';
        $canSearch = true;
        if( $term_title && $term_title->getNamespace() != NS_SPECIAL ) {
@@ -147,10 +157,10 @@ function wfSajaxSearch( $term ) {
                        . '<ul>' .$r .'</ul>' . $more;
        }
 
-       $response = new AjaxResponse( $html );
+       $wgMemc->set( $memckey, array( 'version' => AJAX_SEARCH_VERSION, 'html' => $html ), 30 * 60 );
 
+       $response = new AjaxResponse( $html );
        $response->setCacheDuration( 30*60 );
-
        return $response;
 }