generate result as Store_sql does
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 Jul 2011 10:25:45 +0000 (12:25 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 Jul 2011 10:25:45 +0000 (12:25 +0200)
web_ui.pl

index 9b046b8..f9c3edc 100755 (executable)
--- 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;
        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";
                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 );
        }
        if ( ! $ret ) {
                $ret = $gearman->req( 'SUBMIT_JOB', 'Store_sql', '', $sql );