summaryrefslogtreecommitdiff
path: root/lib/Multi/APIDump.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Multi/APIDump.pm')
-rw-r--r--lib/Multi/APIDump.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Multi/APIDump.pm b/lib/Multi/APIDump.pm
index d3454e72..2ba44156 100644
--- a/lib/Multi/APIDump.pm
+++ b/lib/Multi/APIDump.pm
@@ -79,7 +79,7 @@ sub writejson {
sub votes_gen {
pg_cmd q{
- SELECT vv.vid||' '||vv.uid||' '||vv.vote as l
+ SELECT vv.vid||' '||vv.uid||' '||vv.vote as l, to_char(vv.date, 'YYYY-MM-DD') as d
FROM votes vv
JOIN users u ON u.id = vv.uid
JOIN vn v ON v.id = vv.vid
@@ -91,12 +91,20 @@ sub votes_gen {
return if pg_expect $res, 1;
my $ws = AE::time;
+ # legacy votes v1 file, without date
my $file = "$VNDB::ROOT/www/api/votes.gz";
open my $f, '>:gzip:utf8', "$file~" or die "Writing $file: $!";
printf $f "%s\n", $res->value($_,0) for (0 .. $res->rows-1);
close $f;
rename "$file~", $file or die "Renaming $file: $!";
+ # v2 file with date
+ $file = "$VNDB::ROOT/www/api/votes2.gz";
+ open $f, '>:gzip:utf8', "$file~" or die "Writing $file: $!";
+ printf $f "%s %s\n", $res->value($_,0), $res->value($_,1) for (0 .. $res->rows-1);
+ close $f;
+ rename "$file~", $file or die "Renaming $file: $!";
+
my $wt = AE::time-$ws;
AE::log info => sprintf 'Wrote %s in %.2fs query + %.2fs write, size: %.1fkB, items: %d.',
$file, $time, $wt, (-s $file)/1024, scalar $res->rows;