summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-10-10 16:33:56 +0200
committerYorhel <git@yorhel.nl>2009-10-10 16:33:56 +0200
commit64007de03cba6c0acb8a2782bc5f86bcad946850 (patch)
tree4c9102154c7d3d5903ae67ab382fd3e0f52ccc40
parentecf82cabc44dcd333f0e46c037c7d9c1c4046a0d (diff)
Greatly reduced default number of columns returned by dbUserGet
Most of the columns are only used in some rare situations, so fetching all that information is unecessary. To fetch this information, a what => 'extended' is now required. This change should be most noticable for the user list (now less than half of the previous data is fetched from the database).
-rw-r--r--ChangeLog1
-rw-r--r--lib/VNDB/DB/Users.pm10
-rw-r--r--lib/VNDB/Handler/Users.pm2
-rw-r--r--lib/VNDB/Util/Auth.pm4
4 files changed, 11 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index f7022b15..40fd4eb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@ git - ?
- Changed language selector into a Javascript dropdown
- Added producer role (developer/publisher) to releases
- Display number of unread posts in "My messages" (instead of total threads)
+ - Optimized dbUserGet (mostly for the user list)
2.7 - 2009-09-24
- Improved styling of the threeboxes layout
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index ee4f2b14..593c6415 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -9,7 +9,7 @@ our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserMessageCount dbS
# %options->{ username passwd mail order uid ip registered search results page what }
-# what: stats
+# what: stats extended
sub dbUserGet {
my $s = shift;
my %o = (
@@ -43,8 +43,12 @@ sub dbUserGet {
);
my @select = (
- qw|id username mail rank salt c_votes c_changes show_nsfw show_list skin customcss ip c_tags ign_votes|,
- q|encode(passwd, 'hex') AS passwd|, q|extract('epoch' from registered) as registered|,
+ qw|id username c_votes c_changes show_list c_tags|,
+ q|extract('epoch' from registered) as registered|,
+ $o{what} =~ /extended/ ? (
+ qw|mail rank salt skin customcss show_nsfw ign_votes|,
+ q|encode(passwd, 'hex') AS passwd|
+ ) : (),
$o{what} =~ /stats/ ? (
'(SELECT COUNT(*) FROM rlists WHERE uid = u.id) AS releasecount',
'(SELECT COUNT(DISTINCT rv.vid) FROM rlists rl JOIN releases r ON rl.rid = r.id JOIN releases_vn rv ON rv.rid = r.latest WHERE uid = u.id) AS vncount',
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 1a4b993b..39aecbfc 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -267,7 +267,7 @@ sub edit {
return $self->htmlDenied if !$self->authInfo->{id} || $self->authInfo->{id} != $uid && !$self->authCan('usermod');
# fetch user info (cached if uid == loggedin uid)
- my $u = $self->authInfo->{id} == $uid ? $self->authInfo : $self->dbUserGet(uid => $uid)->[0];
+ my $u = $self->authInfo->{id} == $uid ? $self->authInfo : $self->dbUserGet(uid => $uid, what => 'extended')->[0];
return 404 if !$u->{id};
# check POST data
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index 2595ce5b..a3bf7c29 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -26,7 +26,7 @@ sub authInit {
my $token = substr($cookie, 0, 40);
my $uid = substr($cookie, 40);
return _rmcookie($self) if $uid !~ /^\d+$/ || !$self->dbSessionCheck($uid, $token);
- $self->{_auth} = $self->dbUserGet(uid => $uid)->[0];
+ $self->{_auth} = $self->dbUserGet(uid => $uid, what => 'extended')->[0];
}
@@ -95,7 +95,7 @@ sub _authCheck {
return 0 if !$user || length($user) > 15 || length($user) < 2 || !$pass;
- my $d = $self->dbUserGet(username => $user)->[0];
+ my $d = $self->dbUserGet(username => $user, what => 'extended')->[0];
return 0 if !defined $d->{id} || !$d->{rank};
if(_authEncryptPass($self, $pass, $d->{salt}) eq $d->{passwd}) {