X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=web_ui.pl;h=36d00de60f24684d46addf01a43ebf3182eb0c81;hb=b7ad83dc3edd53f4023f67440774c636e120cec2;hp=9b046b8037d4dc3ada294ca7e6bd006fb811e527;hpb=9d6fc3fd2ae9dda276c889f9a4c8b9b773e3fe77;p=APKPM.git diff --git a/web_ui.pl b/web_ui.pl index 9b046b8..36d00de 100755 --- a/web_ui.pl +++ b/web_ui.pl @@ -91,8 +91,20 @@ get '/table/:table' => sub { my $ret; if ( $limit == 1 ) { my $redis = Redis->new; - $ret = $redis->get( "table.$table.$username" ); + my $json = Mojo::JSON->new->decode( $redis->get( "table.$table.$username" ) ); warn "redis hit table.$table.$username"; + + # generate result as Store_sql does + + my @c = split(/\s+/, $redis->get("pg.$table")); + my ($hash_col) = grep { $c[$_] eq 'h' } 0 .. $#c; + + $ret = { + columns => \@c, + hash_col => $hash_col, + rows => [[ map { $json->{$_} } @c ]], + }; + $ret = Mojo::JSON->new->encode($ret); } if ( ! $ret ) { $ret = $gearman->req( 'SUBMIT_JOB', 'Store_sql', '', $sql ); @@ -131,26 +143,25 @@ sub _gearman_redis { warn "# _gearman_redis $key [$timeout s]"; my $redis = Redis->new; - my $ret; + my $json; - if ( $ret = $redis->get($key) ) { + if ( $json = $redis->get($key) ) { warn "redis hit $key\n"; } else { $gearman->timeout($timeout); - $ret = $gearman->req( 'SUBMIT_JOB', $job, '', $params ); - die "no result for $params" unless $ret; - - $redis->set($key => $ret); + $json = $gearman->req( 'SUBMIT_JOB', $job, '', $params ); + die "no result for $params" unless $json; } - $redis->expire($key => 60); # refresh redis key timeout - - $ret = Mojo::JSON->new->decode( $ret ); + my $ret = Mojo::JSON->new->decode( $json ); if ( ! exists $ret->{error} && ref $ret->{columns} ne 'ARRAY' ) { $ret->{error} = 'query run longer than ' . $gearman->timeout . ' s timeout'; } + $redis->set($key => $json); + $redis->expire($key => 60); # refresh redis key timeout + return $ret; } @@ -179,8 +190,11 @@ get '/gnuplot' => sub { my $dir = $self->app->home->rel_dir('public'); + my $with = $self->param('with') || 'dots'; + my $name = $sql; $name =~ s/\W+//gs; + $name .= $with; $name .= '.png'; warn "# $sql -> $name"; @@ -222,7 +236,6 @@ set xtics nomirror rotate by -90 } my $plot = 'plot '; - my $with = $self->param('with') || 'dots'; foreach my $i ( 1 .. $#{ $ret->{rows}->[0] } ) { $gnuplot .= $plot; $plot = ','; $gnuplot .= qq| '-' using 1:2 with $with title "$c[$i]" |;