use do_high for CRM_search
[APKPM.git] / web_ui.pl
index f9c3edc..36d00de 100755 (executable)
--- a/web_ui.pl
+++ b/web_ui.pl
@@ -143,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;
 }
 
@@ -191,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";
@@ -234,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]" |;