From 0fb313eee43aa5d26e2090f43db45cf638803075 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 10 Jul 2004 01:05:36 +0000 Subject: [PATCH] Load balancing enabled in places where it's thought to be reasonably safe --- includes/Article.php | 4 +++- includes/Block.php | 9 ++++++--- includes/SearchEngine.php | 9 +++++++-- includes/Skin.php | 9 +++++---- includes/SpecialAllpages.php | 6 +++++- includes/SpecialMaintenance.php | 35 +++++++++++++++++++++++++-------- includes/SpecialStatistics.php | 6 +++++- includes/SpecialWatchlist.php | 21 +++++++++++++------- includes/Title.php | 9 ++++++--- 9 files changed, 78 insertions(+), 30 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 748bcec3ad..1af07e3872 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -313,7 +313,7 @@ class Article { # Load the revision (including cur_text) into this object function loadContent( $noredir = false ) { - global $wgOut, $wgMwRedir, $wgRequest, $wgIsPg; + global $wgOut, $wgMwRedir, $wgRequest, $wgIsPg, $wgLoadBalancer; # Query variables :P $oldid = $wgRequest->getVal( 'oldid' ); @@ -397,11 +397,13 @@ class Article { $this->mTitle->mRestrictionsLoaded = true; wfFreeResult( $res ); } else { # oldid set, retrieve historical version + $wgLoadBalancer->force(-1); $oldtable=$wgIsPg?'"old"':'old'; $sql = "SELECT old_namespace,old_title,old_text,old_timestamp,". "old_user,old_user_text,old_comment,old_flags FROM old ". "WHERE old_id={$oldid}"; $res = wfQuery( $sql, DB_READ, $fname ); + $wgLoadBalancer->force(0); if ( 0 == wfNumRows( $res ) ) { return; } diff --git a/includes/Block.php b/includes/Block.php index e8a53e0efd..e5df26241a 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -45,7 +45,8 @@ class Block # Get a ban from the DB, with either the given address or the given username function load( $address = "", $user = 0, $killExpired = true ) { - $fname = 'Block::load'; + global $wgLoadBalancer; + $fname = 'Block::load'; $ret = false; $killed = false; @@ -60,8 +61,10 @@ class Block "' OR ipb_user={$user})"; } - $res = wfQuery( $sql, DB_READ, $fname ); - if ( 0 == wfNumRows( $res ) ) { + $wgLoadBalancer->force(-1); + $res = wfQuery( $sql, DB_READ, $fname ); + $wgLoadBalancer->force(0); + if ( 0 == wfNumRows( $res ) ) { # User is not blocked $this->clear(); } else { diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 53d9e69159..ff17c89958 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -157,7 +157,11 @@ class SearchEngine { { global $wgUser, $wgTitle, $wgOut, $wgLang, $wgRequest; global $wgDisableTextSearch, $wgInputEncoding; - $fname = "SearchEngine::showResults"; + global $wgLoadBalancer; + + $wgLoadBalancer->force(-1); + + $fname = "SearchEngine::showResults"; $search = $wgRequest->getText( 'search' ); @@ -280,7 +284,8 @@ class SearchEngine { $wgOut->addHTML( "

{$sl}

\n" ); $wgOut->addHTML( $powersearch ); } - } + $wgLoadBalancer->force(0); + } function legalSearchChars() { diff --git a/includes/Skin.php b/includes/Skin.php index 866ee65718..a8df31c166 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -12,7 +12,7 @@ require_once( 'Image.php' ); 'standard' => 'Standard', 'nostalgia' => 'Nostalgia', 'cologneblue' => 'CologneBlue' -); +) + $wgExtraSkins; if( $wgUsePHPTal ) { #$wgValidSkinNames[] = 'PHPTal'; #$wgValidSkinNames['davinci'] = 'DaVinci'; @@ -1440,7 +1440,7 @@ class Skin { # Pass a title object, not a title string function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) { - global $wgOut, $wgUser; + global $wgOut, $wgUser, $wgLoadBalancer; if ( $nt->isExternal() ) { $u = $nt->getFullURL(); $link = $nt->getPrefixedURL(); @@ -1467,8 +1467,9 @@ class Skin { } else { $threshold = $wgUser->getOption('stubthreshold') ; if ( $threshold > 0 ) { - $res = wfQuery ( "SELECT LENGTH(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'", DB_READ ) ; - + $wgLoadBalancer->force(-1); + $res = wfQuery ( "SELECT LENGTH(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'", DB_READ ) ; + $wgLoadBalancer->force(0); if ( wfNumRows( $res ) > 0 ) { $s = wfFetchObject( $res ); $size = $s->x; diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php index d848880a65..1cdeaa7de5 100644 --- a/includes/SpecialAllpages.php +++ b/includes/SpecialAllpages.php @@ -2,9 +2,11 @@ function wfSpecialAllpages( $par=NULL ) { - global $indexMaxperpage, $wgRequest; + global $indexMaxperpage, $wgRequest, $wgLoadBalancer; $indexMaxperpage = 480; $from = $wgRequest->getVal( 'from' ); + + $wgLoadBalancer->force(-1); if( $par ) { indexShowChunk( $par ); @@ -13,6 +15,8 @@ function wfSpecialAllpages( $par=NULL ) } else { indexShowToplevel(); } + + $wgLoadBalancer->force(0); } function indexShowToplevel() diff --git a/includes/SpecialMaintenance.php b/includes/SpecialMaintenance.php index e6e75a2ce9..3b16d6a287 100644 --- a/includes/SpecialMaintenance.php +++ b/includes/SpecialMaintenance.php @@ -10,13 +10,15 @@ function sns() function wfSpecialMaintenance( $par=NULL ) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgRequest, $wgLanguageCode; - global $wgMiserMode; + global $wgMiserMode, $wgLoadBalancer; if ( $wgMiserMode ) { $wgOut->addWikiText( wfMsg( "perfdisabled" ) ); return; } + $wgLoadBalancer->force(-1); + $submitmll = $wgRequest->getVal( 'submitmll' ); if( $par ) @@ -24,13 +26,30 @@ function wfSpecialMaintenance( $par=NULL ) else $subfunction = $wgRequest->getText( 'subfunction' ); - if ( $subfunction == "disambiguations" ) return wfSpecialDisambiguations() ; - if ( $subfunction == "doubleredirects" ) return wfSpecialDoubleRedirects() ; - if ( $subfunction == "brokenredirects" ) return wfSpecialBrokenRedirects() ; - if ( $subfunction == "selflinks" ) return wfSpecialSelfLinks() ; - if ( $subfunction == "mispeelings" ) return wfSpecialMispeelings() ; - if ( $subfunction == "missinglanguagelinks" ) return wfSpecialMissingLanguageLinks() ; - if ( !is_null( $submitmll ) ) return wfSpecialMissingLanguageLinks() ; + $done = true; + + if ( $subfunction == "disambiguations" ) { + wfSpecialDisambiguations() ; + } elseif ( $subfunction == "doubleredirects" ) { + wfSpecialDoubleRedirects() ; + } elseif ( $subfunction == "brokenredirects" ) { + wfSpecialBrokenRedirects() ; + } elseif ( $subfunction == "selflinks" ) { + wfSpecialSelfLinks() ; + } elseif ( $subfunction == "mispeelings" ) { + wfSpecialMispeelings() ; + } elseif ( $subfunction == "missinglanguagelinks" ) { + wfSpecialMissingLanguageLinks() ; + } elseif ( !is_null( $submitmll ) ) { + wfSpecialMissingLanguageLinks() ; + } else { + $done = false; + } + + $wgLoadBalancer->force(0); + if ( $done ) { + return; + } $sk = $wgUser->getSkin(); $ns = $wgLang->getNamespaces() ; diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index b842e52525..f53cebc4ea 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -2,9 +2,11 @@ function wfSpecialStatistics() { - global $wgUser, $wgOut, $wgLang, $wgIsPg; + global $wgUser, $wgOut, $wgLang, $wgIsPg, $wgLoadBalancer; $fname = "wfSpecialStatistics"; + $wgLoadBalancer->force(-1); + $wgOut->addHTML( "

" . wfMsg( "sitestats" ) . "

\n" ); $sql = "SELECT COUNT(cur_id) AS total FROM cur"; @@ -50,6 +52,8 @@ function wfSpecialStatistics() $wgLang->formatNum( $total ), $wgLang->formatNum( $admins ), $ap ); $wgOut->addWikiText( $text ); + + $wgLoadBalancer->force(0); } ?> diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index 806eff0e96..aece38b200 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -4,7 +4,7 @@ require_once( "WatchedItem.php" ); function wfSpecialWatchlist() { - global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc; + global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgLoadBalancer; global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname, $wgIsMySQL; global $days, $limit, $target; # From query string $fname = "wfSpecialWatchlist"; @@ -50,18 +50,20 @@ function wfSpecialWatchlist() return; } } - - + + $wgLoadBalancer->force(-1); $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid"; $res = wfQuery( $sql, DB_READ ); $s = wfFetchObject( $res ); $nitems = $s->n; - + $wgLoadBalancer->force(0); if($nitems == 0) { $wgOut->addHTML( wfMsg( "nowatchlist" ) ); return; } - + + $wgLoadBalancer->force(-1); + if ( ! isset( $days ) ) { $big = 1000; if($nitems > $big) { @@ -79,13 +81,14 @@ function wfSpecialWatchlist() $cutoff = false; $npages = wfMsg( "all" ); } else { - $docutoff = "AND cur_timestamp > '" . + $docutoff = "AND cur_timestamp > '" . ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) ) . "'"; - $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'"; + $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'"; $res = wfQuery( $sql, DB_READ ); $s = wfFetchObject( $res ); $npages = $s->n; + } if(isset($_REQUEST['magic'])) { @@ -116,6 +119,7 @@ function wfSpecialWatchlist() wfMsg( "removechecked" ) . "' />\n" . "\n" ); + $wgLoadBalancer->force(0); return; } @@ -167,6 +171,7 @@ function wfSpecialWatchlist() if ( wfNumRows( $res ) == 0 ) { $wgOut->addHTML( "

" . wfMsg( "watchnochange" ) . "

" ); + $wgLoadBalancer->force(0); return; } @@ -187,6 +192,8 @@ function wfSpecialWatchlist() if ( $wgUseWatchlistCache ) { $wgMemc->set( $memckey, $s, $wgWLCacheTimeout); } + + $wgLoadBalancer->force(0); } diff --git a/includes/Title.php b/includes/Title.php index d54c0a9276..7acdc61cdd 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -244,7 +244,8 @@ class Title { function getInterwikiLink( $key ) { global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache; - + global $wgLoadBalancer; + $k = "$wgDBname:interwiki:$key"; if( array_key_exists( $k, $wgTitleInterwikiCache ) ) @@ -257,9 +258,11 @@ class Title { return $s->iw_url; } $dkey = wfStrencode( $key ); - $query = "SELECT iw_url,iw_local FROM interwiki WHERE iw_prefix='$dkey'"; + $wgLoadBalancer->force(-1); + $query = "SELECT iw_url,iw_local FROM interwiki WHERE iw_prefix='$dkey'"; $res = wfQuery( $query, DB_READ, "Title::getInterwikiLink" ); - if(!$res) return ""; + $wgLoadBalancer->force(0); + if(!$res) return ""; $s = wfFetchObject( $res ); if(!$s) { -- 2.20.1