diff options
author | Yorhel <git@yorhel.nl> | 2009-10-10 16:33:56 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-10-10 16:33:56 +0200 |
commit | 64007de03cba6c0acb8a2782bc5f86bcad946850 (patch) | |
tree | 4c9102154c7d3d5903ae67ab382fd3e0f52ccc40 /lib | |
parent | ecf82cabc44dcd333f0e46c037c7d9c1c4046a0d (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).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/DB/Users.pm | 10 | ||||
-rw-r--r-- | lib/VNDB/Handler/Users.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Util/Auth.pm | 4 |
3 files changed, 10 insertions, 6 deletions
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}) { |