Skip to content

Commit

Permalink
Merge pull request #72 from daldoyle/master
Browse files Browse the repository at this point in the history
fixing total calculation in search dataservice
  • Loading branch information
daldoyle authored Nov 16, 2018
2 parents 36b7791 + d368021 commit 49c0bbf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion grnoc-tsds-services.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Summary: GRNOC TSDS Services
Name: grnoc-tsds-services
Version: 1.6.2
Release: 1%{?dist}
Release: 2%{?dist}
License: GRNOC
Group: Measurement
URL: http://globalnoc.iu.edu
Expand Down
2 changes: 1 addition & 1 deletion lib/GRNOC/TSDS/DataService/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ sub _get_search_result_data {
# Since this was the query that determined the later "by" clause it actually
# has the total we want to expose upwards, not the queries below
${$total} += $self->parser()->total() if($meta_ids eq 'ALL');

my @additional_wheres;
foreach my $where_result (@$where_results){
my @arr;
Expand Down
14 changes: 10 additions & 4 deletions lib/GRNOC/TSDS/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2107,14 +2107,20 @@ sub _get_meta_limit_result {
}
])->all();

my $total_count = $limit_result[0]->{'totals'}[0]->{'count'};

$limited_results = $limit_result[0]->{'results'};
my $total_raw = 0;
my $total_count = 0;
foreach my $total_res (@{$limit_result[0]->{'totals'}}){
$total_count++;
$total_raw += $total_res->{'count'};
}

# keep track of how many total matched
# vs just the ones we limit/offset'd
$self->total($total_count);
$self->total_raw($total_count);
$self->total_raw($total_raw);


$limited_results = $limit_result[0]->{'results'};

# Reverse of above, we might get something back
# like "circuit: {name: " and we want to cast that back
Expand Down
15 changes: 13 additions & 2 deletions t/12search.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 37;
use Test::More tests => 39;
use GRNOC::Config;
use GRNOC::Log;
use GRNOC::TSDS::DataService::Search;
Expand All @@ -24,7 +24,18 @@ my $ds = GRNOC::TSDS::DataService::Search->new( config_file => $config_file,
ok( $ds, "search data service connected" );


my $results = $ds->search( search => 'xe-0/1/0.0',
# Test to make sure meta results (total) is correct in case
# where we have no search term and an order by
my $results = $ds->search( search => undef,
measurement_type => ['tsdstest'],
limit => 2,
offset => 0,
order_by => ["name_1", "name_2"]);

is($results->{'total'}, 22, "got correct total for rtr.chic search");
is(@{$results->{'results'}}, 2, "got correctly limited results for rtr.chic search");

$results = $ds->search( search => 'xe-0/1/0.0',
measurement_type => ['tsdstest'] )->{'results'};

is( @$results, 1, "1 search result for xe-0/1/0.0" );
Expand Down

0 comments on commit 49c0bbf

Please sign in to comment.