diff options
author | Yorhel <git@yorhel.nl> | 2009-11-14 16:37:25 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-11-14 16:43:48 +0100 |
commit | ed15643975e6e05ce5e8b9509901f769c86e06b4 (patch) | |
tree | 9cc857ca8217ce345d9b796217cd2858781c15ad /lib/VNDB/DB/VN.pm | |
parent | c7ff7086534cd9de7ce4043eb10c7161401c1b96 (diff) |
Added bayesian rating and vote count to the VN list
It's even realtime! To my surprise this calculation isn't very heavy, or
PostgreSQL is just extremely fast. The GetVN query on /v/all takes 100ms
in the worst case (instead of the usual 30-60ms). Can always cache this
later on.
Diffstat (limited to 'lib/VNDB/DB/VN.pm')
-rw-r--r-- | lib/VNDB/DB/VN.pm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm index bb2c1275..b1fb103b 100644 --- a/lib/VNDB/DB/VN.pm +++ b/lib/VNDB/DB/VN.pm @@ -78,6 +78,8 @@ sub dbVNGet { 'JOIN users u ON u.id = c.requester' : (), $o{what} =~ /relgraph/ ? 'JOIN relgraphs vg ON vg.id = v.rgraph' : (), + $o{what} =~ /rating/ ? + 'LEFT JOIN vn_ratings r ON r.vid = v.id' : (), ); my $tag_ids = $o{tags_include} && join ',', @{$o{tags_include}[1]}; @@ -89,6 +91,7 @@ sub dbVNGet { qw|c.requester c.comments v.latest u.username c.rev c.causedby|, q|extract('epoch' from c.added) as added|) : (), $o{what} =~ /relgraph/ ? 'vg.svg' : (), $o{what} =~ /ranking/ ? '(SELECT COUNT(*)+1 FROM vn iv WHERE iv.hidden = false AND iv.c_popularity > v.c_popularity) AS ranking' : (), + $o{what} =~ /rating/ ? 'r.rating, r.votecount' : (), $tag_ids ? qq|(SELECT AVG(tvb.rating) FROM tags_vn_bayesian tvb WHERE tvb.tag IN($tag_ids) AND tvb.vid = v.id AND spoiler <= $o{tags_include}[0] GROUP BY tvb.vid) AS tagscore| : (), ); @@ -98,7 +101,7 @@ sub dbVNGet { FROM vn_rev vr !s !W - ORDER BY !s|, + ORDER BY !s NULLS LAST|, join(', ', @select), join(' ', @join), \%where, $o{order}, ); |