Skip to content

Commit dfa1780

Browse files
committed
move find method from release document set to query
1 parent 6ca908b commit dfa1780

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

lib/MetaCPAN/Document/Release/Set.pm

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ has query_release => (
2020
by_author
2121
by_author_and_name
2222
by_author_and_names
23+
find
2324
get_contributors
2425
get_files
2526
latest_by_author
@@ -42,21 +43,6 @@ sub _build_query_release {
4243
);
4344
}
4445

45-
sub find {
46-
my ( $self, $name ) = @_;
47-
my $file = $self->filter( {
48-
and => [
49-
{ term => { distribution => $name } },
50-
{ term => { status => 'latest' } }
51-
]
52-
} )->sort( [ { date => 'desc' } ] )->raw->first;
53-
return unless $file;
54-
55-
my $data = $file->{_source}
56-
|| single_valued_arrayref_to_scalar( $file->{fields} );
57-
return $data;
58-
}
59-
6046
sub find_github_based {
6147
shift->filter( {
6248
and => [

lib/MetaCPAN/Query/Release.pm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,5 +1286,29 @@ sub predecessor {
12861286
return $release->{_source};
12871287
}
12881288

1289+
sub find {
1290+
my ( $self, $name ) = @_;
1291+
1292+
my $res = $self->es->search(
1293+
index => $self->index_name,
1294+
type => 'release',
1295+
body => {
1296+
query => {
1297+
bool => {
1298+
must => [
1299+
{ term => { distribution => $name } },
1300+
{ term => { status => 'latest' } },
1301+
],
1302+
},
1303+
},
1304+
sort => [ { date => 'desc' } ],
1305+
size => 1,
1306+
},
1307+
);
1308+
my ($file) = $res->{hits}{hits}[0];
1309+
return undef unless $file;
1310+
return $file->{_source};
1311+
}
1312+
12891313
__PACKAGE__->meta->make_immutable;
12901314
1;

lib/MetaCPAN/Server/Controller/Diff.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sub release : Chained('index') : PathPart('release') : Args(1) {
3333

3434
my ( $latest, $previous );
3535
try {
36-
$latest = $c->model('CPAN::Release')->raw->find($name);
36+
$latest = $c->model('CPAN::Release')->find($name);
3737
$previous
3838
= $c->model('CPAN::Release')->predecessor($name);
3939
}

0 commit comments

Comments
 (0)