summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-11-27 14:48:20 +0100
committerYorhel <git@yorhel.nl>2009-11-27 14:52:20 +0100
commit9613533da2c58af3c64e3bd4ed7b92b22ffd442f (patch)
tree425ee689a98a555638431f92d1bc76cbef22eedd /lib
parent542c1e22daf2648b3babce2ab2050120eec0a9b9 (diff)
DB: Abstracted all ORDER BY clauses in the DB abstraction layer
The ORDER BY was previously specified using an 'order' argument, which would then be directly inserted into the query. The new method is the same as what I used for the public API: two 'sort' and 'reverse' arguments. This should be less error-prone and more readable. This changes quite a lot of code, so I hope I haven't forgotten to update something along the way.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Discussions.pm18
-rw-r--r--lib/VNDB/DB/Releases.pm12
-rw-r--r--lib/VNDB/DB/Tags.pm26
-rw-r--r--lib/VNDB/DB/ULists.pm30
-rw-r--r--lib/VNDB/DB/Users.pm14
-rw-r--r--lib/VNDB/DB/VN.pm18
-rw-r--r--lib/VNDB/Handler/Discussions.pm4
-rw-r--r--lib/VNDB/Handler/Misc.pm10
-rw-r--r--lib/VNDB/Handler/Releases.pm2
-rw-r--r--lib/VNDB/Handler/Tags.pm26
-rw-r--r--lib/VNDB/Handler/ULists.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm2
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm10
-rw-r--r--lib/VNDB/Handler/VNPage.pm4
-rw-r--r--lib/VNDB/Util/CommonHTML.pm1
15 files changed, 108 insertions, 73 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 60487098..deeb7480 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -8,14 +8,14 @@ use Exporter 'import';
our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount dbPostRead|;
-# Options: id, type, iid, results, page, what, notusers
+# Options: id, type, iid, results, page, what, notusers, sort, reverse
# What: boards, boardtitles, firstpost, lastpost
+# Sort: id lastpost
sub dbThreadGet {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
$o{what} ||= '';
- $o{order} ||= 't.id DESC';
my %where = (
$o{id} ? (
@@ -49,13 +49,18 @@ sub dbThreadGet {
'JOIN threads_boards tb ON tb.tid = t.id' : (),
);
+ my $order = sprintf {
+ id => 't.id %s',
+ lastpost => 'tpl.date %s',
+ }->{ $o{sort}||'id' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM threads t
!s
!W
ORDER BY !s|,
- join(', ', @select), join(' ', @join), \%where, $o{order}
+ join(', ', @select), join(' ', @join), \%where, $order
);
if($o{what} =~ /(boards|boardtitles)/ && $#$r >= 0) {
@@ -153,14 +158,13 @@ sub dbThreadCount {
}
-# Options: tid, num, what, order, uid, mindate, hide, page, results
+# Options: tid, num, what, uid, mindate, hide, page, results
# what: user thread
sub dbPostGet {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
$o{what} ||= '';
- $o{order} ||= 'tp.num ASC';
my %where = (
$o{tid} ? (
@@ -192,8 +196,8 @@ sub dbPostGet {
FROM threads_posts tp
!s
!W
- ORDER BY !s|,
- join(', ', @select), join(' ', @join), \%where, $o{order}
+ ORDER BY tp.num ASC|,
+ join(', ', @select), join(' ', @join), \%where
);
return wantarray ? ($r, $np) : $r;
diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm
index d7bddaab..c57b7bc2 100644
--- a/lib/VNDB/DB/Releases.pm
+++ b/lib/VNDB/DB/Releases.pm
@@ -10,15 +10,15 @@ use VNDB::Func 'gtintype';
our @EXPORT = qw|dbReleaseGet dbReleaseAdd dbReleaseEdit|;
-# Options: id vid rev order unreleased page results what date media
+# Options: id vid rev unreleased page results what date media sort reverse
# platforms languages type minage search resolutions freeware doujin
# What: extended changes vn producers platforms media
+# Sort: title released minage
sub dbReleaseGet {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
$o{what} ||= '';
- $o{order} ||= 'rr.released ASC';
my @where = (
!$o{id} && !$o{rev} ? ( 'r.hidden = FALSE' => 0 ) : (),
@@ -77,13 +77,19 @@ sub dbReleaseGet {
(qw|c.requester c.comments r.latest u.username c.rev|, q|extract('epoch' from c.added) as added|) : (),
);
+ my $order = sprintf {
+ title => 'rr.title %s',
+ minage => 'rr.minage %s',
+ released => 'rr.released %s',
+ }->{ $o{sort}||'released' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM releases_rev rr
!s
!W
ORDER BY !s|,
- join(', ', @select), join(' ', @join), \@where, $o{order}
+ join(', ', @select), join(' ', @join), \@where, $order
);
if(@$r) {
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index ee6e0376..d21ed5c4 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -8,12 +8,12 @@ use Exporter 'import';
our @EXPORT = qw|dbTagGet dbTagTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagLinkEdit dbTagStats|;
-# %options->{ id noid name search state meta page results order what }
+# %options->{ id noid name search state meta page results what sort reverse }
# what: parents childs(n) aliases addedby
+# sort: id name added vns
sub dbTagGet {
my $self = shift;
my %o = (
- order => 't.id ASC',
page => 1,
results => 10,
what => '',
@@ -45,13 +45,20 @@ sub dbTagGet {
);
my @join = $o{what} =~ /addedby/ ? 'JOIN users u ON u.id = t.addedby' : ();
+ my $order = sprintf {
+ id => 't.id %s',
+ name => 't.name %s',
+ added => 't.added %s',
+ vns => 't.c_vns %s',
+ }->{ $o{sort}||'id' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM tags t
!s
!W
ORDER BY !s|,
- join(', ', @select), join(' ', @join), \%where, $o{order}
+ join(', ', @select), join(' ', @join), \%where, $order
);
if(@$r && $o{what} =~ /aliases/) {
@@ -147,13 +154,13 @@ sub dbTagLinkEdit {
# Fetch all tags related to a VN or User
-# Argument: %options->{ uid vid minrating results what page order }
+# Argument: %options->{ uid vid minrating results what page sort reverse }
# what: vns
+# sort: name, count, rating
sub dbTagStats {
my($self, %o) = @_;
$o{results} ||= 10;
$o{page} ||= 1;
- $o{order} ||= 't.name ASC';
$o{what} ||= '';
my %where = (
@@ -162,6 +169,13 @@ sub dbTagStats {
$o{vid} ? (
'tv.vid = ?' => $o{vid} ) : (),
);
+
+ my $order = sprintf {
+ name => 't.name %s',
+ count => 'count(*) %s',
+ rating => 'avg(tv.vote) %s',
+ }->{ $o{sort}||'name' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT t.id, t.name, count(*) as cnt, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler
FROM tags t
@@ -171,7 +185,7 @@ sub dbTagStats {
!s
ORDER BY !s|,
\%where, defined $o{minrating} ? "HAVING avg(tv.vote) > $o{minrating}" : '',
- $o{order}
+ $order
);
if(@$r && $o{what} =~ /vns/ && $o{uid}) {
diff --git a/lib/VNDB/DB/ULists.pm b/lib/VNDB/DB/ULists.pm
index 0f54686c..a86d7b12 100644
--- a/lib/VNDB/DB/ULists.pm
+++ b/lib/VNDB/DB/ULists.pm
@@ -35,14 +35,14 @@ sub dbVNListGet {
}
-# %options->{ uid order char voted page results }
+# %options->{ uid char voted page results sort reverse }
+# sort: title vote
# NOTE: this function is mostly copied from 1.x, may need some rewriting...
sub dbVNListList {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
- $o{order} ||= 'vr.title ASC';
$o{voted} ||= 0; # -1: only non-voted, 0: all, 1: only voted
# construct the global WHERE clause
@@ -58,6 +58,11 @@ sub dbVNListList {
$where = '('.$where.') AND (ASCII(vr.title) < 97 OR ASCII(vr.title) > 122) AND (ASCII(vr.title) < 65 OR ASCII(vr.title) > 90)' if defined $o{char} && !$o{char};
$where = '('.$where.') AND vo.vote IS NULL' if $o{voted} == -1;
+ my $order = sprintf {
+ title => 'vr.title %s',
+ vote => 'vo.vote %s NULLS LAST, vr.title ASC',
+ }->{ $o{sort}||'title' }, $o{reverse} ? 'DESC' : 'ASC';
+
# execute query
my($r, $np) = $self->dbPage(\%o, qq|
SELECT vr.vid, vr.title, vr.original, v.c_released, v.c_languages, v.c_platforms, COALESCE(vo.vote, 0) AS vote
@@ -67,7 +72,7 @@ sub dbVNListList {
WHERE $where
ORDER BY !s|,
$o{voted} == 1 ? '' : 'LEFT', $o{uid}, # JOIN if we only want votes, LEFT JOIN if we also want rlist items
- $o{voted} != 1 ? $o{uid} : (), $o{order},
+ $o{voted} != 1 ? $o{uid} : (), $order
);
# fetch releases and link to VNs
@@ -142,11 +147,10 @@ sub dbVNListDel {
}
-# %options->{ uid vid hide order results page what }
+# %options->{ uid vid hide results page what }
# what: user, vn
sub dbVoteGet {
my($self, %o) = @_;
- $o{order} ||= 'n.date DESC';
$o{results} ||= 50;
$o{page} ||= 1;
$o{what} ||= '';
@@ -179,8 +183,8 @@ sub dbVoteGet {
FROM votes n
!s
!W
- ORDER BY !s|,
- join(',', @select), join(' ', @join), \%where, $o{order}
+ ORDER BY n.date DESC|,
+ join(',', @select), join(' ', @join), \%where
);
return wantarray ? ($r, $np) : $r;
@@ -234,12 +238,12 @@ sub dbVoteDel {
}
-# %options->{ uid vid wstat what order page results }
+# %options->{ uid vid wstat what page results sort reverse }
# what: vn
+# sort: title added wstat
sub dbWishListGet {
my($self, %o) = @_;
- $o{order} ||= 'wl.wstat ASC';
$o{page} ||= 1;
$o{results} ||= 50;
$o{what} ||= '';
@@ -258,13 +262,19 @@ sub dbWishListGet {
'JOIN vn_rev vr ON vr.id = v.latest';
}
+ my $order = sprintf {
+ title => 'vr.title %s',
+ added => 'wl.added %s',
+ wstat => 'wl.wstat %2$s, vr.title ASC',
+ }->{ $o{sort}||'wstat' }, $o{reverse} ? 'DESC' : 'ASC', $o{reverse} ? 'ASC' : 'DESC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM wlists wl
!s
!W
ORDER BY !s|,
- $select, join(' ', @join), \%where, $o{order},
+ $select, join(' ', @join), \%where, $order,
);
return wantarray ? ($r, $np) : $r;
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index 39429a02..f8fdfe3f 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -8,12 +8,12 @@ use Exporter 'import';
our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserMessageCount dbSessionAdd dbSessionDel|;
-# %options->{ username passwd mail session order uid ip registered search results page what }
+# %options->{ username passwd mail session uid ip registered search results page what sort reverse }
# what: stats extended
+# sort: username registered votes changes tags
sub dbUserGet {
my $s = shift;
my %o = (
- order => 'username ASC',
page => 1,
results => 10,
what => '',
@@ -65,13 +65,21 @@ sub dbUserGet {
$o{session} ? 'JOIN sessions s ON s.uid = u.id' : (),
);
+ my $order = sprintf {
+ username => 'u.username %s',
+ registered => 'u.registered %s',
+ votes => 'NOT u.show_list, u.c_votes %s',
+ changes => 'u.c_changes %s',
+ tags => 'u.c_tags %s',
+ }->{ $o{sort}||'username' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $s->dbPage(\%o, q|
SELECT !s
FROM users u
!s
!W
ORDER BY !s|,
- join(', ', @select), join(' ', @join), \%where, $o{order}
+ join(', ', @select), join(' ', @join), \%where, $order
);
return wantarray ? ($r, $np) : $r;
}
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 55df48ee..feaa9bd0 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -10,13 +10,13 @@ use Encode 'decode_utf8';
our @EXPORT = qw|dbVNGet dbVNAdd dbVNEdit dbVNImageId dbVNCache dbScreenshotAdd dbScreenshotGet dbScreenshotRandom|;
-# Options: id, rev, char, search, lang, platform, tags_include, tags_exclude, results, page, order, what
+# Options: id, rev, char, search, lang, platform, tags_include, tags_exclude, results, page, what, sort, reverse
# What: extended anime relations screenshots relgraph rating ranking changes
+# Sort: id rel pop rating title tagscore rand
sub dbVNGet {
my($self, %o) = @_;
$o{results} ||= 10;
$o{page} ||= 1;
- $o{order} ||= 'vr.title ASC';
$o{what} ||= '';
my %where = (
@@ -97,13 +97,23 @@ sub dbVNGet {
qq|(SELECT AVG(tvh.rating) FROM tags_vn_inherit tvh WHERE tvh.tag IN($tag_ids) AND tvh.vid = v.id AND spoiler <= $o{tags_include}[0] GROUP BY tvh.vid) AS tagscore| : (),
);
+ my $order = sprintf {
+ id => 'id %s',
+ rel => 'c_released %s',
+ pop => 'c_popularity %s NULLS LAST',
+ rating => 'c_rating %s NULLS LAST',
+ title => 'title %s',
+ tagscore => 'tagscore %s',
+ rand => 'RANDOM()',
+ }->{ $o{sort}||'title' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM vn_rev vr
!s
!W
- ORDER BY !s NULLS LAST|,
- join(', ', @select), join(' ', @join), \%where, $o{order},
+ ORDER BY !s|,
+ join(', ', @select), join(' ', @join), \%where, $order,
);
if($o{what} =~ /relgraph/) {
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 12b55029..fc477de2 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -295,7 +295,7 @@ sub board {
results => 50,
page => $f->{p},
what => 'firstpost lastpost boardtitles',
- order => $type eq 'an' ? 't.id DESC' : 'tpl.date DESC',
+ sort => $type eq 'an' ? 'id' : 'lastpost', reverse => 1,
);
$self->htmlHeader(title => $title, noindex => !@$list || $type eq 'u');
@@ -349,7 +349,7 @@ sub index {
results => 5,
page => 1,
what => 'firstpost lastpost boardtitles',
- order => 'tpl.date DESC',
+ sort => 'lastpost', reverse => 1,
);
h1 class => 'boxtitle';
a href => "/t/$_", mt "_dboard_$_";
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index dbb348be..e762df8f 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -78,7 +78,7 @@ sub homepage {
# Announcements
td;
- my $an = $self->dbThreadGet(type => 'an', order => 't.id DESC', results => 2);
+ my $an = $self->dbThreadGet(type => 'an', sort => 'id', reverse => 1, results => 2);
h1;
a href => '/t/an', mt '_home_announcements';
end;
@@ -98,7 +98,7 @@ sub homepage {
h1;
a href => '/t', mt '_home_recentposts';
end;
- my $posts = $self->dbThreadGet(what => 'lastpost boardtitles', results => 10, order => 'tpl.date DESC', notusers => 1);
+ my $posts = $self->dbThreadGet(what => 'lastpost boardtitles', results => 10, sort => 'lastpost', reverse => 1, notusers => 1);
ul;
for (@$posts) {
my $boards = join ', ', map mt("_dboard_$_->{type}").($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
@@ -120,7 +120,7 @@ sub homepage {
h1;
a href => '/v/rand', mt '_home_randomvn';
end;
- my $random = $self->dbVNGet(results => 10, order => 'RANDOM()');
+ my $random = $self->dbVNGet(results => 10, sort => 'rand');
ul;
for (@$random) {
li;
@@ -154,7 +154,7 @@ sub homepage {
h1;
a href => strftime('/r?ma=%Y%m%d;o=d;s=released', gmtime), mt '_home_justreleased';
end;
- my $justrel = $self->dbReleaseGet(results => 10, order => 'rr.released DESC', unreleased => 0, what => 'platforms');
+ my $justrel = $self->dbReleaseGet(results => 10, sort => 'released', reverse => 1, unreleased => 0, what => 'platforms');
ul;
for (@$justrel) {
li;
@@ -300,7 +300,7 @@ sub docpage {
$ii;
}eg;
s{^:TOP5CONTRIB:$}{
- my $l = $self->dbUserGet(results => 6, order => 'c_changes DESC');
+ my $l = $self->dbUserGet(results => 6, sort => 'changes', reverse => 1);
'<dl>'.join('', map $_->{id} == 1 ? () :
sprintf('<dt><a href="/u%d">%s</a></dt><dd>%d</dd>', $_->{id}, $_->{username}, $_->{c_changes}),
@$l).'</dl>';
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index daeffb9e..b699e596 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -517,7 +517,7 @@ sub browse {
$f->{do} ? (doujin => $f->{do}) : (),
);
my($list, $np) = !@filters ? ([], 0) : $self->dbReleaseGet(
- order => $f->{s}.($f->{o}eq'd'?' DESC':' ASC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
page => $f->{p},
results => 50,
what => 'platforms',
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 5412be02..2a55fd8f 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -38,19 +38,11 @@ sub tagpage {
my $tagspoil = $self->reqCookie('tagspoil');
$f->{m} = $tagspoil =~ /^[0-2]$/ ? $tagspoil : 0 if $f->{m} == -1;
- my $sortcol = {qw|
- rel c_released
- pop c_popularity
- rating c_rating
- title title
- tagscore tagscore
- |}->{$f->{s}};
-
my($list, $np) = $t->{meta} || $t->{state} != 2 ? ([],0) : $self->dbVNGet(
what => 'rating',
results => 50,
page => $f->{p},
- order => $sortcol.($f->{o} eq 'a' ? ' ASC' : ' DESC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
tags_include => [ $f->{m}, [$tag ]],
);
@@ -309,7 +301,7 @@ sub taglist {
return 404 if $f->{_err};
my($t, $np) = $self->dbTagGet(
- order => $f->{s}.($f->{o}eq'd'?' DESC':' ASC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
page => $f->{p},
results => 50,
state => $f->{t},
@@ -457,7 +449,7 @@ sub usertags {
return 404 if !$u;
my $f = $self->formValidate(
- { name => 's', required => 0, default => 'cnt', enum => [ qw|cnt name| ] },
+ { name => 's', required => 0, default => 'count', enum => [ qw|count name| ] },
{ name => 'o', required => 0, default => 'd', enum => [ 'a','d' ] },
{ name => 'p', required => 0, default => 1, template => 'int' },
);
@@ -467,7 +459,7 @@ sub usertags {
my($list, $np) = $self->dbTagStats(
uid => $uid,
page => $f->{p},
- order => ($f->{s}eq'cnt'?'COUNT(*)':'name').($f->{o}eq'a'?' ASC':' DESC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
what => 'vns',
);
@@ -497,8 +489,8 @@ sub usertags {
b id => 'expandall';
lit '<i>&#9656;</i> '.mt('_tagu_col_num').' ';
end;
- lit $f->{s} eq 'cnt' && $f->{o} eq 'a' ? "\x{25B4}" : qq|<a href="/u$u->{id}/tags?o=a;s=cnt">\x{25B4}</a>|;
- lit $f->{s} eq 'cnt' && $f->{o} eq 'd' ? "\x{25BE}" : qq|<a href="/u$u->{id}/tags?o=d;s=cnt">\x{25BE}</a>|;
+ lit $f->{s} eq 'count' && $f->{o} eq 'a' ? "\x{25B4}" : qq|<a href="/u$u->{id}/tags?o=a;s=count">\x{25B4}</a>|;
+ lit $f->{s} eq 'count' && $f->{o} eq 'd' ? "\x{25BE}" : qq|<a href="/u$u->{id}/tags?o=d;s=count">\x{25BE}</a>|;
end;
},
[ mt('_tagu_col_name'), 'name' ],
@@ -553,7 +545,7 @@ sub tagindex {
# Recently added
td;
a class => 'right', href => '/g/list', mt '_tagidx_browseall';
- my $r = $self->dbTagGet(order => 'added DESC', results => 10, state => 2);
+ my $r = $self->dbTagGet(sort => 'added', reverse => 1, results => 10, state => 2);
h1 mt '_tagidx_recent';
ul;
for (@$r) {
@@ -568,7 +560,7 @@ sub tagindex {
# Popular
td;
- $r = $self->dbTagGet(order => 'c_vns DESC', meta => 0, results => 10);
+ $r = $self->dbTagGet(sort => 'vns', reverse => 1, meta => 0, results => 10);
h1 mt '_tagidx_popular';
ul;
for (@$r) {
@@ -583,7 +575,7 @@ sub tagindex {
# Moderation queue
td;
h1 mt '_tagidx_queue';
- $r = $self->dbTagGet(state => 0, order => 'added DESC', results => 10);
+ $r = $self->dbTagGet(state => 0, sort => 'added', reverse => 1, results => 10);
ul;
li mt '_tagidx_queue_empty' if !@$r;
for (@$r) {
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index 6a0d6c9e..9d6885ad 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -122,7 +122,7 @@ sub wishlist {
my($list, $np) = $self->dbWishListGet(
uid => $uid,
- order => $f->{s}.' '.($f->{o} eq 'a' ? ($f->{s} eq 'wstat' ? 'DESC' : 'ASC' ) : ($f->{s} eq 'wstat' ? 'ASC' : 'DESC')).($f->{s} eq 'wstat' ? ', title ASC' : ''),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
$f->{f} != -1 ? (wstat => $f->{f}) : (),
what => 'vn',
results => 50,
@@ -229,7 +229,7 @@ sub vnlist {
uid => $uid,
results => 50,
page => $f->{p},
- order => $f->{s}.' '.($f->{o} eq 'd' ? 'DESC' : 'ASC').($f->{s} eq 'vote' ? ', title ASC' : ''),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
voted => $f->{v},
$f->{c} ne 'all' ? (char => $f->{c}) : (),
);
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index fbbbfc5d..e9c97198 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -474,7 +474,7 @@ sub list {
end;
my($list, $np) = $self->dbUserGet(
- order => ($f->{s} eq 'changes' || $f->{s} eq 'tags' ? 'c_' : $f->{s} eq 'votes' ? 'NOT show_list, c_' : '').$f->{s}.($f->{o} eq 'a' ? ' ASC' : ' DESC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
$char ne 'all' ? (
firstchar => $char ) : (),
results => 50,
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index c7944a46..43e8b3cb 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -55,21 +55,13 @@ sub list {
$f->{s} = 'title' if !@ti && $f->{s} eq 'tagscore';
$f->{o} = $f->{s} eq 'tagscore' ? 'd' : 'a' if !$f->{o};
- my $sortcol = {qw|
- rel c_released
- pop c_popularity
- rating c_rating
- title title
- tagscore tagscore
- |}->{$f->{s}};
-
my($list, $np) = $self->dbVNGet(
what => 'rating',
$char ne 'all' ? ( char => $char ) : (),
$f->{q} ? ( search => $f->{q} ) : (),
results => 50,
page => $f->{p},
- order => $sortcol.($f->{o} eq 'a' ? ' ASC' : ' DESC'),
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
$f->{pl}[0] ? ( platform => $f->{pl} ) : (),
$f->{ln}[0] ? ( lang => $f->{ln} ) : (),
@ti ? (tags_include => [ $f->{sp}, \@ti ]) : (),
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 2a333337..cc469848 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -16,7 +16,7 @@ YAWF::register(
sub rand {
my $self = shift;
- $self->resRedirect('/v'.$self->dbVNGet(results => 1, order => 'RANDOM()')->[0]{id}, 'temp');
+ $self->resRedirect('/v'.$self->dbVNGet(results => 1, sort => 'rand')->[0]{id}, 'temp');
}
@@ -146,7 +146,7 @@ sub page {
clearfloat;
# tags
- my $t = $self->dbTagStats(vid => $v->{id}, order => 'avg(tv.vote) DESC', minrating => 0, results => 999);
+ my $t = $self->dbTagStats(vid => $v->{id}, sort => 'rating', reverse => 1, minrating => 0, results => 999);
if(@$t) {
div id => 'tagops';
# NOTE: order of these links is hardcoded in JS
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index e616be41..e42b10e6 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -359,7 +359,6 @@ sub htmlVoteStats {
my $recent = $self->dbVoteGet(
$type.'id' => $obj->{id},
results => 8,
- order => 'date DESC',
what => $type eq 'v' ? 'user' : 'vn',
hide => $type eq 'v',
hide_ign => $type eq 'v',