X-Git-Url: http://git.rot13.org/?p=angular-drzb;a=blobdiff_plain;f=angular-server.pl;h=3da071c45c29a2d0b81e77e43ae2e0b91a83e1a7;hp=e6298fc937a3254781b50ab6f1e92dc229dcdb1e;hb=HEAD;hpb=15d484fdc0010544bb9185741652f140c6930264 diff --git a/angular-server.pl b/angular-server.pl index e6298fc..3da071c 100755 --- a/angular-server.pl +++ b/angular-server.pl @@ -19,9 +19,13 @@ my $couchdb_database = 'drzb2013v2'; my $couchdb_view = "http://10.60.0.92:5984/_utils/document.html?$couchdb_database"; my $client = Mojo::UserAgent->new; +our $view_cache; + sub _couchdb_put { my ( $url, $data ) = @_; + $view_cache = undef; + $data->{'$entity'} = $1 if $url =~ m{/(\w+)\.\d+/$/}; my $json = Mojo::JSON->new->encode( $data ); @@ -216,8 +220,6 @@ any [ 'post' ] => '/data/:database/:entity' => sub { # CouchDB proxy for _design _view -our $view_cache; - get '/:database/_design/:design/_view/:view' => sub { my $self = shift; my $format = $self->param('format'); @@ -296,7 +298,16 @@ function(doc) { } elsif ( $format eq 'key_distinct' ) { my $found; - $json->{rows} = [ grep { ++$found->{ $_->{key} } == 1 } @{ $json->{rows} } ]; + my @rows = grep { + push @{ $found->{ $_->{key} } }, $_->{id}; + $#{ $found->{ $_->{key} } } == 0; # take just first registration + } @{ $json->{rows} }; + + $json->{rows} = [ map { + $_->{distinct_ids} = $found->{ $_->{key} }; + $_; + } @rows ]; + $json->{distinct_rows} = scalar @{ $json->{rows} }; warn "## distinct stats ", dump( $found );