summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/ULists.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-12-11 17:26:12 +0100
committerYorhel <git@yorhel.nl>2008-12-11 17:26:12 +0100
commit8ee44b95d35dce42840416761af190846ab09fff (patch)
tree267bffff784b573b65f960aaf1637e71cf89941e /lib/VNDB/DB/ULists.pm
parentfeeb60277ef3d20ef049bd648cf29542af2687c1 (diff)
Selective table join for dbVoteGet
Only fetch information we actually need.
Diffstat (limited to 'lib/VNDB/DB/ULists.pm')
-rw-r--r--lib/VNDB/DB/ULists.pm28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/VNDB/DB/ULists.pm b/lib/VNDB/DB/ULists.pm
index 212388d0..829ee537 100644
--- a/lib/VNDB/DB/ULists.pm
+++ b/lib/VNDB/DB/ULists.pm
@@ -127,12 +127,14 @@ sub dbVNListDel {
}
-# %options->{ uid vid hide order results page }
+# %options->{ uid vid hide order results page what }
+# what: user, vn
sub dbVoteGet {
my($self, %o) = @_;
$o{order} ||= 'n.date DESC';
$o{results} ||= 50;
$o{page} ||= 1;
+ $o{what} ||= '';
my %where = (
$o{uid} ? ( 'n.uid = ?' => $o{uid} ) : (),
@@ -140,15 +142,29 @@ sub dbVoteGet {
$o{hide} ? ( 'u.show_list = TRUE' => 1 ) : (),
);
+ my @select = (
+ qw|n.vid n.vote n.date n.uid|,
+ $o{what} =~ /user/ ? ('u.username') : (),
+ $o{what} =~ /vn/ ? (qw|vr.title vr.original|) : (),
+ );
+
+ my @join = (
+ $o{what} =~ /vn/ ? (
+ 'JOIN vn v ON v.id = n.vid',
+ 'JOIN vn_rev vr ON vr.id = v.latest'
+ ) : (),
+ $o{what} =~ /user/ || $o{hide} ? (
+ 'JOIN users u ON u.id = n.uid'
+ ) : (),
+ );
+
my($r, $np) = $self->dbPage(\%o, q|
- SELECT n.vid, vr.title, vr.original, n.vote, n.date, n.uid, u.username
+ SELECT !s
FROM votes n
- JOIN vn v ON v.id = n.vid
- JOIN vn_rev vr ON vr.id = v.latest
- JOIN users u ON u.id = n.uid
+ !s
!W
ORDER BY !s|,
- \%where, $o{order}
+ join(',', @select), join(' ', @join), \%where, $o{order}
);
return wantarray ? ($r, $np) : $r;