Skip to content

Commit f33faa3

Browse files
authored
Merge pull request #979 from metacpan/haarg/normal-structures
return normal structures even when there are 0 results from queries
2 parents 86b08d1 + 04fa772 commit f33faa3

File tree

8 files changed

+8
-22
lines changed

8 files changed

+8
-22
lines changed

lib/MetaCPAN/Model/Search.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ sub search_for_first_result {
4747
my ( $self, $search_term ) = @_;
4848
my $es_query = $self->build_query($search_term);
4949
my $es_results = $self->run_query( file => $es_query );
50-
return unless $es_results->{hits}{total};
5150

5251
my $data = $es_results->{hits}{hits}[0];
5352
single_valued_arrayref_to_scalar( $data->{fields} );

lib/MetaCPAN/Query/Favorite.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ with 'MetaCPAN::Query::Role::Common';
88

99
sub agg_by_distributions {
1010
my ( $self, $distributions, $user ) = @_;
11-
return unless $distributions;
11+
return {
12+
favorites => {},
13+
myfavorites => {},
14+
took => 0,
15+
}
16+
unless $distributions;
1217

1318
my $body = {
1419
size => 0,

lib/MetaCPAN/Query/File.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ sub dir {
3737
body => $body,
3838
}
3939
);
40-
return unless $data->{hits}{total};
4140

4241
my $dir = [ map { $_->{fields} } @{ $data->{hits}{hits} } ];
4342
single_valued_arrayref_to_scalar($dir);

lib/MetaCPAN/Query/Mirror.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ sub search {
5353
@sort,
5454
},
5555
);
56-
return unless $ret->{hits}{total};
5756

5857
my $data = [
5958
map +{

lib/MetaCPAN/Query/Package.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ sub get_modules {
2828
}
2929
);
3030

31-
return unless $res->{hits}{total};
3231
return +{ modules =>
3332
[ map { $_->{_source}{module_name} } @{ $res->{hits}{hits} } ] };
3433
}

lib/MetaCPAN/Query/Permission.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ sub by_author {
2626
type => 'permission',
2727
body => $body,
2828
);
29-
return unless $ret->{hits}{total};
3029

3130
my $data = [
3231
sort { $a->{module_name} cmp $b->{module_name} }
@@ -42,7 +41,8 @@ sub by_modules {
4241

4342
my @modules = map +{ term => { module_name => $_ } },
4443
grep defined, @{$modules};
45-
return unless @modules;
44+
return { permissions => [] }
45+
unless @modules;
4646

4747
my $body = {
4848
query => {
@@ -56,7 +56,6 @@ sub by_modules {
5656
type => 'permission',
5757
body => $body,
5858
);
59-
return unless $ret->{hits}{total};
6059

6160
my $data = [
6261
sort { $a->{module_name} cmp $b->{module_name} }

lib/MetaCPAN/Query/Rating.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ sub by_distributions {
3131
type => 'rating',
3232
body => $body,
3333
);
34-
return unless $ret->{hits}{total};
3534

3635
my %distributions = map { $_->{key} => $_->{ratings_dist} }
3736
@{ $ret->{aggregations}{ratings}{buckets} };

lib/MetaCPAN/Query/Release.pm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ sub by_author_and_name {
364364
type => 'release',
365365
body => $body,
366366
);
367-
return unless $ret->{hits}{total};
368367

369368
my $data = $ret->{hits}{hits}[0]{_source};
370369
single_valued_arrayref_to_scalar($data);
@@ -412,7 +411,6 @@ sub by_author_and_names {
412411
type => 'release',
413412
body => $body,
414413
);
415-
return unless $ret->{hits}{total};
416414

417415
my @releases;
418416
for my $hit ( @{ $ret->{hits}{hits} } ) {
@@ -454,7 +452,6 @@ sub by_author {
454452
type => 'release',
455453
body => $body,
456454
);
457-
return unless $ret->{hits}{total};
458455

459456
my $data = [ map { $_->{_source} } @{ $ret->{hits}{hits} } ];
460457
single_valued_arrayref_to_scalar($data);
@@ -491,7 +488,6 @@ sub latest_by_distribution {
491488
type => 'release',
492489
body => $body,
493490
);
494-
return unless $ret->{hits}{total};
495491

496492
my $data = $ret->{hits}{hits}[0]{_source};
497493
single_valued_arrayref_to_scalar($data);
@@ -526,7 +522,6 @@ sub latest_by_author {
526522
type => 'release',
527523
body => $body,
528524
);
529-
return unless $ret->{hits}{total};
530525

531526
my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
532527
single_valued_arrayref_to_scalar($data);
@@ -553,7 +548,6 @@ sub all_by_author {
553548
type => 'release',
554549
body => $body,
555550
);
556-
return unless $ret->{hits}{total};
557551

558552
my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
559553
single_valued_arrayref_to_scalar($data);
@@ -583,7 +577,6 @@ sub versions {
583577
type => 'release',
584578
body => $body,
585579
);
586-
return unless $ret->{hits}{total};
587580

588581
my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
589582
single_valued_arrayref_to_scalar($data);
@@ -676,7 +669,6 @@ sub requires {
676669
sort => [$sort],
677670
}
678671
);
679-
return {} unless $ret->{hits}{total};
680672

681673
return +{
682674
data => [ map { $_->{_source} } @{ $ret->{hits}{hits} } ],
@@ -718,7 +710,6 @@ sub _get_latest_release {
718710
fields => [qw< name author >],
719711
},
720712
);
721-
return unless $release->{hits}{total};
722713

723714
my ($release_info) = map { $_->{fields} } @{ $release->{hits}{hits} };
724715
single_valued_arrayref_to_scalar($release_info);
@@ -749,7 +740,6 @@ sub _get_provided_modules {
749740
size => 999,
750741
}
751742
);
752-
return unless $provided_modules->{hits}{total};
753743

754744
return [
755745
map { $_->{name} }
@@ -805,7 +795,6 @@ sub _get_depended_releases {
805795
sort => $sort,
806796
}
807797
);
808-
return unless $depended->{hits}{total};
809798

810799
return +{
811800
data => [ map { $_->{_source} } @{ $depended->{hits}{hits} } ],
@@ -858,7 +847,6 @@ sub recent {
858847
type => 'release',
859848
body => $body,
860849
);
861-
return unless $ret->{hits}{total};
862850

863851
my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
864852
single_valued_arrayref_to_scalar($data);
@@ -950,7 +938,6 @@ sub modules {
950938
type => 'file',
951939
body => $body,
952940
);
953-
return unless $ret->{hits}{total};
954941

955942
my @files = map +{
956943
%{ ( single_valued_arrayref_to_scalar( $_->{fields} ) )[0] },

0 commit comments

Comments
 (0)