diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt
index d6b81c1ed..5d2af9146 100644
--- a/docs/changelog/6.x.x.txt
+++ b/docs/changelog/6.x.x.txt
@@ -62,6 +62,10 @@
gain, but it was already really fast, so relatively users aren't likely to
notice the difference. However, this change helps in the overall
scalability of WebGUI under load.
+ - Added the ability to use replicated slave databases to lessen the load on
+ the master database. This will have no effect on single database users, but
+ can add a tremendous amount of scalability on large WebGUI sites that use
+ database replication.
6.0.3
diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm
index 08cba6bf6..d6459183d 100644
--- a/lib/WebGUI.pm
+++ b/lib/WebGUI.pm
@@ -68,8 +68,7 @@ sub _processFunctions {
if ($session{form}{wid} eq "new") {
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
} else {
- $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId="
- .$session{form}{wid});
+ $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid},WebGUI::SQL->getSlave);
if (${$wobject}{namespace} eq "") {
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or "
."corrupt, but was requested "
@@ -83,7 +82,7 @@ sub _processFunctions {
wobject,WobjectProxy
where wobject.wobjectId=WobjectProxy.wobjectId
and wobject.pageId=".$session{page}{pageId}."
- and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId});
+ and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId},WebGUI::SQL->getSlave);
${$wobject}{_WobjectProxy} = $proxyWobjectId;
}
unless (${$wobject}{pageId} == $session{page}{pageId}
diff --git a/lib/WebGUI/Forum/Post.pm b/lib/WebGUI/Forum/Post.pm
index 9aba2c8cd..95aa2e7c8 100644
--- a/lib/WebGUI/Forum/Post.pm
+++ b/lib/WebGUI/Forum/Post.pm
@@ -184,7 +184,7 @@ sub getReplies {
$query .= "(status='approved'";
}
$query .= " or userId=$session{user}{userId}) order by forumPostId";
- my $sth = WebGUI::SQL->read($query);
+ my $sth = WebGUI::SQL->read($query,WebGUI::SQL->getSlave);
while (my @data = $sth->array) {
push(@replies,WebGUI::Forum::Post->new($data[0]));
}
diff --git a/lib/WebGUI/Forum/Thread.pm b/lib/WebGUI/Forum/Thread.pm
index 999dccf80..e8d61197d 100644
--- a/lib/WebGUI/Forum/Thread.pm
+++ b/lib/WebGUI/Forum/Thread.pm
@@ -172,7 +172,7 @@ sub getNextThread {
my ($self) = @_;
unless (exists $self->{_next}) {
my ($nextId) = WebGUI::SQL->quickArray("select min(forumThreadId) from forumThread where forumId=".$self->get("forumId")."
- and forumThreadId>".$self->get("forumThreadId"));
+ and forumThreadId>".$self->get("forumThreadId"),WebGUI::SQL->getSlave);
$self->{_next} = WebGUI::Forum::Thread->new($nextId);
}
return $self->{_next};
@@ -214,7 +214,7 @@ sub getPreviousThread {
my ($self) = @_;
unless (exists $self->{_previous}) {
my ($nextId) = WebGUI::SQL->quickArray("select max(forumThreadId) from forumThread where forumId=".$self->get("forumId")."
- and forumThreadId<".$self->get("forumThreadId"));
+ and forumThreadId<".$self->get("forumThreadId"),WebGUI::SQL->getSlave);
$self->{_previous} = WebGUI::Forum::Thread->new($nextId);
}
return $self->{_previous};
diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm
index 81e4fc604..a9e51aded 100644
--- a/lib/WebGUI/HTML.pm
+++ b/lib/WebGUI/HTML.pm
@@ -198,7 +198,7 @@ sub processReplacements {
$content =~ s/\Q$searchFor/$replaceWith/gs;
}
} else {
- my $sth = WebGUI::SQL->read("select searchFor,replaceWith from replacements");
+ my $sth = WebGUI::SQL->read("select searchFor,replaceWith from replacements",WebGUI::SQL->getSlave);
while (my ($searchFor,$replaceWith) = $sth->array) {
$session{replacements}{$searchFor} = $replaceWith;
$content =~ s/\Q$searchFor/$replaceWith/gs;
diff --git a/lib/WebGUI/Macro/GroupText.pm b/lib/WebGUI/Macro/GroupText.pm
index 6d1dac963..2b2af67a9 100644
--- a/lib/WebGUI/Macro/GroupText.pm
+++ b/lib/WebGUI/Macro/GroupText.pm
@@ -19,7 +19,7 @@ use WebGUI::Session;
#-------------------------------------------------------------------
sub process {
my @param = WebGUI::Macro::getParams($_[0]);
- my ($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($param[0]));
+ my ($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($param[0]),WebGUI::SQL->getSlave);
$groupId = 3 if ($groupId eq "");
if (WebGUI::Grouping::isInGroup($groupId)) {
return $param[1];
diff --git a/lib/WebGUI/Macro/H_homeLink.pm b/lib/WebGUI/Macro/H_homeLink.pm
index 3cc45ee6a..7e3fe2b14 100644
--- a/lib/WebGUI/Macro/H_homeLink.pm
+++ b/lib/WebGUI/Macro/H_homeLink.pm
@@ -23,7 +23,7 @@ sub process {
if ($session{setting}{defaultPage} == $session{page}{pageId}) {
$temp = $session{page}{urlizedTitle};
} else {
- ($temp) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=$session{setting}{defaultPage}");
+ ($temp) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=$session{setting}{defaultPage}",WebGUI::SQL->getSlave);
}
$temp = WebGUI::URL::gateway($temp);
if ($param[0] ne "linkonly") {
diff --git a/lib/WebGUI/Macro/LastModified.pm b/lib/WebGUI/Macro/LastModified.pm
index 77c1ec21c..b406d5939 100644
--- a/lib/WebGUI/Macro/LastModified.pm
+++ b/lib/WebGUI/Macro/LastModified.pm
@@ -24,7 +24,7 @@ sub process {
$format = '%z' if ($format eq "");
$output = "";
- ($time) = WebGUI::SQL->quickArray("SELECT max(lastEdited) FROM wobject where pageId=$session{page}{pageId}");
+ ($time) = WebGUI::SQL->quickArray("SELECT max(lastEdited) FROM wobject where pageId=$session{page}{pageId}",WebGUI::SQL->getSlave);
if ($time) {
$output = $label.epochToHuman($time,$format);
}
diff --git a/lib/WebGUI/Macro/RandomImage.pm b/lib/WebGUI/Macro/RandomImage.pm
index c5107cccd..a2d67163a 100644
--- a/lib/WebGUI/Macro/RandomImage.pm
+++ b/lib/WebGUI/Macro/RandomImage.pm
@@ -23,11 +23,11 @@ sub process {
my $collateralFolderId = 0;
if ($param[0] ne "") {
($collateralFolderId) = WebGUI::SQL->quickArray("select collateralFolderId from collateralFolder
- where name=".quote($param[0]));
+ where name=".quote($param[0]),WebGUI::SQL->getSlave);
$collateralFolderId = 0 unless ($collateralFolderId);
}
my @images = WebGUI::SQL->buildArray("select collateralId from collateral
- where collateralType='image' and collateralFolderId=".$collateralFolderId);
+ where collateralType='image' and collateralFolderId=".$collateralFolderId,WebGUI::SQL->getSlave);
if (my $collateral = WebGUI::Collateral->new($images[rand($#images+1)])) {
return 'get("parameters").' />';
} else {
diff --git a/lib/WebGUI/Macro/RandomSnippet.pm b/lib/WebGUI/Macro/RandomSnippet.pm
index a6fd86590..da38dc649 100644
--- a/lib/WebGUI/Macro/RandomSnippet.pm
+++ b/lib/WebGUI/Macro/RandomSnippet.pm
@@ -23,11 +23,11 @@ sub process {
my $collateralFolderId = 0;
if ($param[0] ne "") {
($collateralFolderId) = WebGUI::SQL->quickArray("select collateralFolderId from collateralFolder
- where name=".quote($param[0]));
+ where name=".quote($param[0]),WebGUI::SQL->getSlave);
$collateralFolderId = 0 unless ($collateralFolderId);
}
my @snippets = WebGUI::SQL->buildArray("select collateralId from collateral
- where collateralType='snippet' and collateralFolderId=".$collateralFolderId);
+ where collateralType='snippet' and collateralFolderId=".$collateralFolderId,WebGUI::SQL->getSlave);
if (my $collateral = WebGUI::Collateral->new($snippets[rand($#snippets+1)])) {
return $collateral->get("parameters");
} else {
diff --git a/lib/WebGUI/Macro/RootTitle.pm b/lib/WebGUI/Macro/RootTitle.pm
index 8d4869662..51b844877 100644
--- a/lib/WebGUI/Macro/RootTitle.pm
+++ b/lib/WebGUI/Macro/RootTitle.pm
@@ -21,7 +21,7 @@ use WebGUI::URL;
sub process {
my ($sth, %data, $output);
tie %data, 'Tie::CPHash';
- %data = WebGUI::SQL->quickHash("select pageId,parentId,title,urlizedTitle from page where pageId=".($_[0] || $session{page}{parentId}));
+ %data = WebGUI::SQL->quickHash("select pageId,parentId,title,urlizedTitle from page where pageId=".($_[0] || $session{page}{parentId}),WebGUI::SQL->getSlave);
if ($data{parentId} == 0) {
$output = $data{title} || $session{page}{title};
} else {
diff --git a/lib/WebGUI/Macro/SQL.pm b/lib/WebGUI/Macro/SQL.pm
index 18f759c33..6798e3a1e 100644
--- a/lib/WebGUI/Macro/SQL.pm
+++ b/lib/WebGUI/Macro/SQL.pm
@@ -21,7 +21,7 @@ sub process {
my ($statement, $format) = WebGUI::Macro::getParams(shift);
$format = '^0;' if ($format eq "");
if ($statement =~ /^\s*select/i || $statement =~ /^\s*show/i || $statement =~ /^\s*describe/i) {
- my $sth = WebGUI::SQL->unconditionalRead($statement);
+ my $sth = WebGUI::SQL->unconditionalRead($statement,WebGUI::SQL->getSlave);
unless ($sth->errorCode < 1) {
return '
SQL Macro Failed: '.$sth->errorMessage.'
'; } else { diff --git a/lib/WebGUI/Macro/r_printable.pm b/lib/WebGUI/Macro/r_printable.pm index 534c2364a..a378915fd 100644 --- a/lib/WebGUI/Macro/r_printable.pm +++ b/lib/WebGUI/Macro/r_printable.pm @@ -28,7 +28,7 @@ sub process { } $temp = WebGUI::URL::append($session{env}{REQUEST_URI},$append); if ($param[1] ne "") { - ($styleId) = WebGUI::SQL->quickArray("select styleId from style where name=".quote($param[1])); + ($styleId) = WebGUI::SQL->quickArray("select styleId from style where name=".quote($param[1]),WebGUI::SQL->getSlave); if ($styleId != 0) { $temp = WebGUI::URL::append($temp,'styleId='.$styleId); } diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm index 881fb29b1..c24a43096 100644 --- a/lib/WebGUI/Operation/Profile.pm +++ b/lib/WebGUI/Operation/Profile.pm @@ -41,7 +41,7 @@ sub getRequiredProfileFields { #$f = WebGUI::HTMLForm->new(); $a = WebGUI::SQL->read("select * from userProfileField, userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId and - userProfileField.required=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); + userProfileField.required=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber",WebGUI::SQL->getSlave); while($data = $a->hashRef) { my %hash = (); $method = $data->{dataType}; @@ -225,7 +225,8 @@ sub www_viewProfile { return $vars->{displayTitle}.WebGUI::International::get(862) if($u->profileField("publicProfile") < 1); return WebGUI::Privilege::insufficient() if(!WebGUI::Grouping::isInGroup(2)); $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId - and userProfileCategory.visible=1 and userProfileField.visible=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); + and userProfileCategory.visible=1 and userProfileField.visible=1 order by userProfileCategory.sequenceNumber, + userProfileField.sequenceNumber",WebGUI::SQL->getSlave); while (%data = $a->hash) { $category = eval $data{categoryName}; if ($category ne $previousCategory) { diff --git a/lib/WebGUI/Page.pm b/lib/WebGUI/Page.pm index e1ee3c191..ecb6d2476 100644 --- a/lib/WebGUI/Page.pm +++ b/lib/WebGUI/Page.pm @@ -223,7 +223,7 @@ sub canView { if ($pageId eq $session{page}{pageId}) { %page = %{$session{page}}; } else { - %page = WebGUI::SQL->quickHash("select ownerId,groupIdView,startDate,endDate from page where pageId=$pageId"); + %page = WebGUI::SQL->quickHash("select ownerId,groupIdView,startDate,endDate from page where pageId=$pageId",WebGUI::SQL->getSlave); } if ($session{user}{userId} == $page{ownerId}) { return 1; @@ -404,7 +404,7 @@ sub generate { .moveUpIcon('op=movePageUp') .moveDownIcon('op=movePageDown') .cutIcon('op=cutPage'); - my $sth = WebGUI::SQL->read("select * from wobject where pageId=".$session{page}{pageId}." order by sequenceNumber, wobjectId"); + my $sth = WebGUI::SQL->read("select * from wobject where pageId=".$session{page}{pageId}." order by sequenceNumber, wobjectId",WebGUI::SQL->getSlave); while (my $wobject = $sth->hashRef) { my $wobjectToolbar = wobjectIcon() .deleteIcon('func=delete&wid='.${$wobject}{wobjectId}) @@ -420,8 +420,8 @@ sub generate { } if (${$wobject}{namespace} eq "WobjectProxy") { my $originalWobject = $wobject; - my ($wobjectProxy) = WebGUI::SQL->quickHashRef("select * from WobjectProxy where wobjectId=".${$wobject}{wobjectId}); - $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$wobjectProxy->{proxiedWobjectId}); + my ($wobjectProxy) = WebGUI::SQL->quickHashRef("select * from WobjectProxy where wobjectId=".${$wobject}{wobjectId},WebGUI::SQL->getSlave); + $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$wobjectProxy->{proxiedWobjectId},WebGUI::SQL->getSlave); if (${$wobject}{namespace} eq "") { $wobject = $originalWobject; } else { diff --git a/lib/WebGUI/Paginator.pm b/lib/WebGUI/Paginator.pm index f9f79a967..294822b4d 100644 --- a/lib/WebGUI/Paginator.pm +++ b/lib/WebGUI/Paginator.pm @@ -513,7 +513,7 @@ A boolean indicating that the query should be read unconditionally. Defaults to sub setDataByQuery { my ($sth, $rowCount, @row); my ($self, $sql, $dbh, $unconditional) = @_; - $dbh ||= $session{dbh}; + $dbh ||= WebGUI::SQL->getSlave; if ($unconditional) { $sth = WebGUI::SQL->unconditionalRead($sql,$dbh); return $sth->errorMessage if ($sth->errorCode > 0); diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 475db3f85..36532fd2d 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -65,6 +65,8 @@ Package for interfacing with SQL databases. This package implements Perl DBI fun $hashRef = WebGUI::SQL->quickHashRef($sql); $text = WebGUI::SQL->quickTab($sql); + $dbh = WebGUI::SQL->getSlave; + $id = getNextId("wobjectId"); $string = quote($string); @@ -75,6 +77,12 @@ These methods are available from this package: =cut +#------------------------------------------------------------------- +sub _getDefaultDb { + return $WebGUI::Session::session{dbh}; +} + + #------------------------------------------------------------------- =head2 array ( ) @@ -387,6 +395,25 @@ sub getRow { return $row; } + +#------------------------------------------------------------------- + +=head2 getSlave ( ) + +Returns a random slave database handler, if one is defined, otherwise it returns undef. Likewise if admin mode is on it returns undef. + +=cut + +sub getSlave { + if ($WebGUI::Session::session{var}{adminOn}) { + return undef; + } else { + return $WebGUI::Session::session{slave}->[rand @{$WebGUI::Session::session{slave}}]; + } +} + + + #------------------------------------------------------------------- =head2 hash ( ) @@ -450,7 +477,7 @@ A database handler. Defaults to the WebGUI default database handler. sub prepare { my $class = shift; my $sql = shift; - my $dbh = shift || $WebGUI::Session::session{dbh}; + my $dbh = shift || _getDefaultDb(); if ($WebGUI::Session::session{setting}{showDebug}) { push(@{$WebGUI::Session::session{SQLquery}},$sql); } @@ -622,7 +649,7 @@ sub quickTab { #------------------------------------------------------------------- -=head2 quote ( string ) +=head2 quote ( string [ , dbh ] ) Returns a string quoted and ready for insert into the database. @@ -634,13 +661,18 @@ NOTE: This is not a regular method, but is an exported subroutine. Any scalar variable that needs to be escaped to be inserted into the database. +=item dbh + +The database handler. Defaults to the WebGUI database handler. + =back =cut sub quote { - my $value = $_[0]; #had to add this here cuz Tie::CPHash variables cause problems otherwise. - return $WebGUI::Session::session{dbh}->quote($value); + my $value = shift; #had to add this here cuz Tie::CPHash variables cause problems otherwise. + my $dbh = shift || _getDefaultDb(); + return $dbh->quote($value); } @@ -780,7 +812,7 @@ By default this method uses the WebGUI database handler. However, you may choose sub unconditionalRead { my $class = shift; my $sql = shift; - my $dbh = shift || $WebGUI::Session::session{dbh}; + my $dbh = shift || _getDefaultDb(); if ($WebGUI::Session::session{setting}{showDebug}) { push(@{$WebGUI::Session::session{SQLquery}},$sql); } @@ -815,7 +847,7 @@ By default this method uses the WebGUI database handler. However, you may choose sub write { my $class = shift; my $sql = shift; - my $dbh = shift || $WebGUI::Session::session{dbh}; + my $dbh = shift || _getDefaultDb(); if ($WebGUI::Session::session{setting}{showDebug}) { push(@{$WebGUI::Session::session{SQLquery}},$sql); } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index c4ea24723..744488147 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -314,6 +314,11 @@ sub open { $session{dbh}->{LongReadLen} = 512 * 1024; $session{dbh}->{LongTruncOk} = 1; } + foreach (1..3) { + if ($session{config}{"dbslave".$_}) { + push(@{$session{slave}},DBI->connect($session{config}{"dbslave".$_}{dsn},$session{config}{"dbslave".$_}{user},$session{config}{"dbslave".$_}{pass})); + } + } ###---------------------------- ### global system settings (from settings table) $session{setting} = WebGUI::SQL->buildHashRef("select name,value from settings"); diff --git a/lib/WebGUI/Style.pm b/lib/WebGUI/Style.pm index 3d745889e..aebabb0ec 100644 --- a/lib/WebGUI/Style.pm +++ b/lib/WebGUI/Style.pm @@ -19,7 +19,6 @@ use strict; use Tie::CPHash; use WebGUI::International; use WebGUI::Session; -use WebGUI::SQL; use WebGUI::Template; diff --git a/lib/WebGUI/Template.pm b/lib/WebGUI/Template.pm index d584a901c..06622057e 100644 --- a/lib/WebGUI/Template.pm +++ b/lib/WebGUI/Template.pm @@ -108,7 +108,7 @@ Defaults to "page". Specify the namespace of the template to retrieve. sub get { my $templateId = shift || 1; my $namespace = shift || "page"; - return WebGUI::SQL->quickHashRef("select * from template where templateId=".$templateId." and namespace=".quote($namespace)); + return WebGUI::SQL->quickHashRef("select * from template where templateId=".$templateId." and namespace=".quote($namespace),WebGUI::SQL->getSlave); } @@ -130,7 +130,7 @@ Defaults to "page". Specify the namespace to build the list for. sub getList { my $namespace = $_[0] || "page"; - return WebGUI::SQL->buildHashRef("select templateId,name from template where namespace=".quote($namespace)." and showInForms=1 order by name"); + return WebGUI::SQL->buildHashRef("select templateId,name from template where namespace=".quote($namespace)." and showInForms=1 order by name",WebGUI::SQL->getSlave); } @@ -184,7 +184,7 @@ sub process { $params{double_file_cache} = 1; } unless (-f $file->getPath) { - my ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$templateId." and namespace=".quote($namespace)); + my ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$templateId." and namespace=".quote($namespace),WebGUI::SQL->getSlave); $file->saveFromScalar($template); } return _execute(\%params,$vars); diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index f845ae628..9c9e5a7ff 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -347,7 +347,7 @@ sub getCollateral { if ($keyValue eq "new" || $keyValue eq "") { return {$keyName=>"new"}; } else { - return WebGUI::SQL->quickHashRef("select * from $tableName where $keyName=".quote($keyValue)); + return WebGUI::SQL->quickHashRef("select * from $tableName where $keyName=".quote($keyValue),WebGUI::SQL->getSlave); } } @@ -766,7 +766,7 @@ sub new { my %fullProperties; my $extra; unless ($properties->{wobjectId} eq "new") { - $extra = WebGUI::SQL->quickHashRef("select * from ".$properties->{namespace}." where wobjectId='".$properties->{wobjectId}."'"); + $extra = WebGUI::SQL->quickHashRef("select * from ".$properties->{namespace}." where wobjectId='".$properties->{wobjectId}."'",WebGUI::SQL->getSlave); } tie %fullProperties, 'Tie::CPHash'; %fullProperties = (%{$properties},%{$extra}); @@ -838,7 +838,7 @@ sub processTemplate { ); if (defined $self->get("_WobjectProxy")) { $vars{isShortcut} = 1; - my ($originalPageURL) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=".$self->get("pageId")); + my ($originalPageURL) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=".$self->get("pageId"),WebGUI::SQL->getSlave); $vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->get("wobjectId")); } my $namespace = $namespace || $self->get("namespace"); diff --git a/lib/WebGUI/Wobject/Article.pm b/lib/WebGUI/Wobject/Article.pm index b0b71572a..316c7f2f4 100644 --- a/lib/WebGUI/Wobject/Article.pm +++ b/lib/WebGUI/Wobject/Article.pm @@ -23,7 +23,6 @@ use WebGUI::International; use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; -use WebGUI::SQL; use WebGUI::URL; use WebGUI::Wobject; diff --git a/lib/WebGUI/Wobject/EventsCalendar.pm b/lib/WebGUI/Wobject/EventsCalendar.pm index 417d4db9d..7d912427f 100644 --- a/lib/WebGUI/Wobject/EventsCalendar.pm +++ b/lib/WebGUI/Wobject/EventsCalendar.pm @@ -371,7 +371,7 @@ sub www_view { if ($_[0]->get("startMonth") eq "first") { my $query = "select min(startDate) from EventsCalendar_event"; $query .= " where wobjectId=".$_[0]->get("wobjectId") unless ($_[0]->get("isMaster")); - ($minDate) = WebGUI::SQL->quickArray($query); + ($minDate) = WebGUI::SQL->quickArray($query,WebGUI::SQL->getSlave); } elsif ($_[0]->get("startMonth") eq "january") { $minDate = WebGUI::DateTime::humanToEpoch(WebGUI::DateTime::epochToHuman("","%y")."-01-01 00:00:00"); } else { @@ -383,7 +383,7 @@ sub www_view { if ($_[0]->get("endMonth") eq "last") { my $query = "select max(endDate) from EventsCalendar_event"; $query .= " where wobjectId=".$_[0]->get("wobjectId") unless ($_[0]->get("isMaster")); - ($maxDate) = WebGUI::SQL->quickArray($query); + ($maxDate) = WebGUI::SQL->quickArray($query,WebGUI::SQL->getSlave); } elsif ($_[0]->get("endMonth") eq "after12") { $maxDate = WebGUI::DateTime::addToDate($minDate,1,0,0); } elsif ($_[0]->get("endMonth") eq "after9") { @@ -423,7 +423,7 @@ sub www_view { $query .= " (endDate>=$monthStart and endDate<=$monthEnd) and (startDate>=$monthStart and startDate<=$monthEnd) order by startDate,endDate"; my %events; my %previous; - my $sth = WebGUI::SQL->read($query); + my $sth = WebGUI::SQL->read($query,WebGUI::SQL->getSlave); while (my $event = $sth->hashRef) { my $eventLength = WebGUI::DateTime::getDaysInInterval($event->{startDate},$event->{endDate}); my $startYear = epochToHuman($event->{startDate},"%y"); @@ -539,7 +539,7 @@ sub www_view { sub www_viewEvent { my ($output, %event, %var, $id); tie %event, 'Tie::CPHash'; - %event = WebGUI::SQL->quickHash("select * from EventsCalendar_event where EventsCalendar_eventId=$session{form}{eid}"); + %event = WebGUI::SQL->quickHash("select * from EventsCalendar_event where EventsCalendar_eventId=$session{form}{eid}",WebGUI::SQL->getSlave); $var{title} = $event{name}; $var{"start.label"} = WebGUI::International::get(14,$_[0]->get("namespace")); $var{"start.date"} = epochToHuman($event{startDate},"%z"); @@ -556,13 +556,13 @@ sub www_viewEvent { my $query = "select EventsCalendar_eventId from EventsCalendar_event where EventsCalendar_eventId<>$event{EventsCalendar_eventId}"; $query .= " and wobjectId=".$_[0]->get("wobjectId") unless ($_[0]->get("isMaster")); $query .= " and startDate<=$event{startDate} order by startDate desc, endDate desc"; - ($id) = WebGUI::SQL->quickArray($query); + ($id) = WebGUI::SQL->quickArray($query,WebGUI::SQL->getSlave); $var{"previous.label"} = '«'.WebGUI::International::get(92,$_[0]->get("namespace")); $var{"previous.url"} = WebGUI::URL::page("func=viewEvent&wid=".$_[0]->get("wobjectId")."&eid=".$id) if ($id); $query = "select EventsCalendar_eventId from EventsCalendar_event where EventsCalendar_eventId<>$event{EventsCalendar_eventId}"; $query .= " and wobjectId=".$_[0]->get("wobjectId") unless ($_[0]->get("isMaster")); $query .= " and startDate>=$event{startDate} order by startDate, endDate"; - ($id) = WebGUI::SQL->quickArray($query); + ($id) = WebGUI::SQL->quickArray($query,WebGUI::SQL->getSlave); $var{"next.label"} = WebGUI::International::get(93,$_[0]->get("namespace")).'»'; $var{"next.url"} = WebGUI::URL::page("func=viewEvent&wid=".$_[0]->get("wobjectId")."&eid=".$id) if ($id); $var{description} = $event{description}; diff --git a/lib/WebGUI/Wobject/USS.pm b/lib/WebGUI/Wobject/USS.pm index 7216dc165..207abb2cc 100644 --- a/lib/WebGUI/Wobject/USS.pm +++ b/lib/WebGUI/Wobject/USS.pm @@ -696,7 +696,7 @@ sub www_view { $imageURL = ""; } ($responses) = WebGUI::SQL->quickArray("select count(*) from forumPost left join forumThread on - forumThread.forumThreadId=forumPost.forumThreadId where forumThread.forumId=".$row->{forumId}); + forumThread.forumThreadId=forumPost.forumThreadId where forumThread.forumId=".$row->{forumId},WebGUI::SQL->getSlave); my $quickurl = 'wid='.$_[0]->get("wobjectId").'&sid='.$page->[$i]->{USS_submissionId}.'&func='; my $controls = deleteIcon($quickurl.'deleteSubmission') .editIcon($quickurl.'editSubmission'); @@ -767,7 +767,7 @@ sub www_viewRSS { ("select USS_submissionId, content, title, " . "dateSubmitted, username from USS_submission " . "where USS_id = " .$session{dbh}->quote($_[0]->get("USS_id")) . " and status='Approved' " . - "order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder")." limit " . $numResults); + "order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder")." limit " . $numResults,WebGUI::SQL->getSlave); while (my $row = $res->{_sth}->fetchrow_arrayref()) { my ($sid, $content, $title, $dateSubmitted, $username) = @@ -841,13 +841,13 @@ sub www_viewSubmission { $var{"post.label"} = WebGUI::International::get(20,$_[0]->get("namespace")); @data = WebGUI::SQL->quickArray("select max(USS_submissionId) from USS_submission where USS_id=".$_[0]->get("USS_id")." and USS_submissionId<$submission->{USS_submissionId} - and (userId=$submission->{userId} or status='Approved')"); + and (userId=$submission->{userId} or status='Approved')",WebGUI::SQL->getSlave); $var{"previous.more"} = ($data[0] ne ""); $var{"previous.url"} = WebGUI::URL::page('func=viewSubmission&sid='.$data[0].'&wid='.$session{form}{wid}); $var{"previous.label"} = WebGUI::International::get(58,$_[0]->get("namespace")); @data = WebGUI::SQL->quickArray("select min(USS_submissionId) from USS_submission where USS_id=$submission->{USS_id} and USS_submissionId>$submission->{USS_submissionId} - and (userId=$submission->{userId} or status='Approved')"); + and (userId=$submission->{userId} or status='Approved')",WebGUI::SQL->getSlave); $var{"next.more"} = ($data[0] ne ""); $var{"next.url"} = WebGUI::URL::page('func=viewSubmission&sid='.$data[0].'&wid='.$session{form}{wid}); $var{"next.label"} = WebGUI::International::get(59,$_[0]->get("namespace"));