Skip to content

Commit c0a2b28

Browse files
committed
move find method from release document set to query
1 parent b95053c commit c0a2b28

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
@@ -1282,5 +1282,29 @@ sub predecessor {
12821282
return $release->{_source};
12831283
}
12841284

1285+
sub find {
1286+
my ( $self, $name ) = @_;
1287+
1288+
my $res = $self->es->search(
1289+
index => $self->index_name,
1290+
type => 'release',
1291+
body => {
1292+
query => {
1293+
bool => {
1294+
must => [
1295+
{ term => { distribution => $name } },
1296+
{ term => { status => 'latest' } },
1297+
],
1298+
},
1299+
},
1300+
sort => [ { date => 'desc' } ],
1301+
size => 1,
1302+
},
1303+
);
1304+
my ($file) = $res->{hits}{hits}[0];
1305+
return undef unless $file;
1306+
return $file->{_source};
1307+
}
1308+
12851309
__PACKAGE__->meta->make_immutable;
12861310
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 = $c->model('CPAN::Release')->predecessor($name);
3838
}
3939
catch {

0 commit comments

Comments
 (0)