Index: trunk/phase3/includes/SearchEngine.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | var $addtoquery = array(); |
11 | 11 | var $namespacesToSearch = array(); |
12 | 12 | var $alternateTitle; |
| 13 | + var $all_titles = false; |
13 | 14 | |
14 | 15 | function SearchEngine( $text ) |
15 | 16 | { |
— | — | @@ -529,6 +530,15 @@ |
530 | 531 | /* static */ function getTitlesByLength($aLength, $aNamespace = 0){ |
531 | 532 | global $wgMemc, $wgDBname; |
532 | 533 | |
| 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 | + |
533 | 543 | $mkey = "$wgDBname:titlesbylength:$aLength:$aNamespace"; |
534 | 544 | $mkeyts = "$wgDBname:titlesbylength:createtime"; |
535 | 545 | $ts = $wgMemc->get( $mkeyts ); |
— | — | @@ -541,6 +551,7 @@ |
542 | 552 | } |
543 | 553 | |
544 | 554 | $wgMemc->set( $mkeyts, time() ); |
| 555 | + |
545 | 556 | $res = wfQuery("SELECT cur_title, cur_namespace FROM cur", DB_READ); |
546 | 557 | $titles = array(); // length, ns, [titles] |
547 | 558 | while( $obj = wfFetchObject( $res ) ){ |
— | — | @@ -555,12 +566,14 @@ |
556 | 567 | $wgMemc->set( $mkey, $title_arr, 3600 * 24 ); |
557 | 568 | } |
558 | 569 | } |
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(); |
560 | 575 | } |
561 | 576 | } |
562 | 577 | |
563 | 578 | /* private static */ function SearchEngine_pcmp($a, $b){ return $a[0] - $b[0]; } |
564 | 579 | |
565 | | - |
566 | | - |
567 | 580 | ?> |