diff options
author | Yorhel <git@yorhel.nl> | 2009-11-15 10:46:54 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-11-15 10:50:19 +0100 |
commit | 7f1b892cb46c8f713a3bb7c5ea94de2f7aa42508 (patch) | |
tree | e4cf9fff72f8aefd541e52cbe47bf79284fe228f /lib/VNDB/DB/Users.pm | |
parent | cd566ad416c19c81e7574491c78b81a7c609c5d2 (diff) |
Auth: Combined dbSessionCheck into dbUserGet
This one query is a bit faster than the two queries executed seperately, and
with a query that is executed on each pageview it does matter.
Ideally, the dbUserMessageCount() is cached and fetched with the same query,
this should save another 1-2ms. But this is probably not worth the extra code
it would require.
Diffstat (limited to 'lib/VNDB/DB/Users.pm')
-rw-r--r-- | lib/VNDB/DB/Users.pm | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm index 593c6415..39429a02 100644 --- a/lib/VNDB/DB/Users.pm +++ b/lib/VNDB/DB/Users.pm @@ -5,10 +5,10 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserMessageCount dbSessionAdd dbSessionDel dbSessionCheck|; +our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserMessageCount dbSessionAdd dbSessionDel|; -# %options->{ username passwd mail order uid ip registered search results page what } +# %options->{ username passwd mail session order uid ip registered search results page what } # what: stats extended sub dbUserGet { my $s = shift; @@ -40,6 +40,8 @@ sub dbUserGet { 'registered > to_timestamp(?)' => $o{registered} ) : (), $o{search} ? ( 'username ILIKE ?' => "%$o{search}%") : (), + $o{session} ? ( + q|s.token = decode(?, 'hex')| => $o{session} ) : (), ); my @select = ( @@ -59,12 +61,17 @@ sub dbUserGet { ) : (), ); + my @join = ( + $o{session} ? 'JOIN sessions s ON s.uid = u.id' : (), + ); + my($r, $np) = $s->dbPage(\%o, q| SELECT !s FROM users u + !s !W ORDER BY !s|, - join(', ', @select), \%where, $o{order} + join(', ', @select), join(' ', @join), \%where, $o{order} ); return wantarray ? ($r, $np) : $r; } @@ -147,15 +154,5 @@ sub dbSessionDel { } -# Queries the database for the validity of a session -# Returns 1 if corresponding session found, 0 if not -# uid, token -sub dbSessionCheck { - my($s, @o) = @_; - return $s->dbRow( - q|SELECT count(uid) AS count FROM sessions WHERE uid = ? AND token = decode(?, 'hex') LIMIT 1|, @o - )->{count}||0; -} - - 1; + |