Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Oops, fix getDB()

  • Loading branch information...
commit d2f33250babafb804d0be74619a4729721508fda 1 parent f80f8b8
@pudge pudge authored
Showing with 12 additions and 13 deletions.
  1. +12 −13 Slash/DB/MySQL/MySQL.pm
View
25 Slash/DB/MySQL/MySQL.pm
@@ -2276,22 +2276,21 @@ sub getDB {
my($self, $db_type) = @_;
my $cache = getCurrentCache();
+ my $found = [];
if ($cache->{'dbs'} && (($_getDBs_cached_nextcheck || 0) > time)) {
- my $vu_ar = $cache->{'dbs'}{$db_type};
-# print STDERR gmtime() . " $$ getDB returning cache for '$db_type'"
-# . " time='" . time . "'"
-# . " nextcheck in " . ($_getDBs_cached_nextcheck - time) . " secs\n";
- return "" if !$vu_ar || !@$vu_ar;
- return $vu_ar->[ rand @$vu_ar ];
+ $found = $cache->{'dbs'}{$db_type};
+ return "" if !$found || !@$found;
+ } else {
+ my $dbs = $self->sqlSelectAllHashref('id', '*', 'dbs',
+ 'type=' . $self->sqlQuote($db_type) . " AND isalive='yes'"
+ );
+ for (keys %$dbs) {
+ my $db = $dbs->{$_};
+ push @$found, ($db) x $db->{weight};
+ }
}
- my $users = $self->sqlSelectColArrayref('virtual_user', 'dbs',
- 'type=' . $self->sqlQuote($db_type) . " AND isalive='yes'");
- my $weighted = [];
- for my $db (@$users) {
- push @$weighted, ($db) x $db->{weight};
- }
- return $weighted->[rand @$weighted];
+ return $found->[rand @$found]{virtual_user};
}
} # end closure surrounding getDBs and getDB

0 comments on commit d2f3325

Please sign in to comment.
Something went wrong with that request. Please try again.