r2468 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2467‎ | r2468 | r2469 >
Date:12:03, 11 February 2004
Author:e23
Status:old
Tags:
Comment:
Fixed bug causing warnings. Fixed problem with repeated heavy SQL queries on non-memcached setups.
Modified paths:
  • /trunk/phase3/includes/SearchEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SearchEngine.php
@@ -9,6 +9,7 @@
1010 var $addtoquery = array();
1111 var $namespacesToSearch = array();
1212 var $alternateTitle;
 13+ var $all_titles = false;
1314
1415 function SearchEngine( $text )
1516 {
@@ -529,6 +530,15 @@
530531 /* static */ function getTitlesByLength($aLength, $aNamespace = 0){
531532 global $wgMemc, $wgDBname;
532533
 534+ // to avoid multiple costly SELECTs in case of no memcached
 535+ if( $this->all_titles ){
 536+ if( isset( $this->all_titles[$aLength][$aNamespace] ) ){
 537+ return $this->all_titles[$aLength][$aNamespace];
 538+ } else {
 539+ return array();
 540+ }
 541+ }
 542+
533543 $mkey = "$wgDBname:titlesbylength:$aLength:$aNamespace";
534544 $mkeyts = "$wgDBname:titlesbylength:createtime";
535545 $ts = $wgMemc->get( $mkeyts );
@@ -541,6 +551,7 @@
542552 }
543553
544554 $wgMemc->set( $mkeyts, time() );
 555+
545556 $res = wfQuery("SELECT cur_title, cur_namespace FROM cur", DB_READ);
546557 $titles = array(); // length, ns, [titles]
547558 while( $obj = wfFetchObject( $res ) ){
@@ -555,12 +566,14 @@
556567 $wgMemc->set( $mkey, $title_arr, 3600 * 24 );
557568 }
558569 }
559 - return $titles[$aLength][$aNamespace];
 570+ $this->all_titles = $titles;
 571+ if( isset( $titles[$aLength][$aNamespace] ) )
 572+ return $titles[$aLength][$aNamespace];
 573+ else
 574+ return array();
560575 }
561576 }
562577
563578 /* private static */ function SearchEngine_pcmp($a, $b){ return $a[0] - $b[0]; }
564579
565 -
566 -
567580 ?>

Status & tagging log