Skip to content

Commit 81abd3b

Browse files
mavorgoalders
authored andcommitted
no_latest: use callback.
1 parent fcf92f9 commit 81abd3b

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

lib/MetaCPAN/Web/Controller/Author.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ sub index : Chained('root') PathPart('') Args(0) {
6363

6464
my @all_fav = map { $_->{fields}->{distribution} }
6565
@{ $faves_data->{hits}->{hits} };
66-
my $noLatest = $c->model('API::Release')->no_latest(@all_fav);
66+
my $noLatest = $c->model('API::Release')->no_latest(@all_fav)->recv;
67+
$took += $noLatest->{took} || 0;
6768

6869
$faves = [
6970
map {
7071
my $distro = $_->{fields}->{distribution};
71-
$noLatest->{$distro} ? () : $_->{fields};
72+
$noLatest->{no_latest}->{$distro} ? () : $_->{fields};
7273
} @{ $faves_data->{hits}->{hits} }
7374
];
7475
$self->single_valued_arrayref_to_scalar($faves);

lib/MetaCPAN/Web/Model/API/Release.pm

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,13 @@ sub topuploaders {
446446

447447
sub no_latest {
448448
my ( $self, @distributions ) = @_;
449+
my $cv = $self->cv;
449450

450451
# If there are no distributions return
451452
return {} unless (@distributions);
452453

453454
@distributions = uniq @distributions;
454-
my $result = $self->request(
455+
$self->request(
455456
'/release/_search',
456457
{
457458
size => scalar @distributions,
@@ -468,17 +469,28 @@ sub no_latest {
468469
},
469470
fields => [qw(distribution status)]
470471
}
471-
)->recv;
472-
473-
my @latest
474-
= map { $_->{fields}->{distribution} } @{ $result->{hits}->{hits} };
475-
476-
my %no_latest = map {
477-
my $distro = $_;
478-
( first { $_ eq $distro } @latest ) ? () : ( $distro, 1 );
479-
} @distributions;
480-
481-
return \%no_latest;
472+
)->cb(
473+
sub {
474+
my $data = shift->recv;
475+
my @latest
476+
= map { $_->{fields}->{distribution} }
477+
@{ $data->{hits}->{hits} };
478+
$cv->send(
479+
{
480+
took => $data->{took},
481+
no_latest => {
482+
map {
483+
my $distro = $_;
484+
( first { $_ eq $distro } @latest )
485+
? ()
486+
: ( $distro, 1 );
487+
} @distributions
488+
}
489+
}
490+
);
491+
}
492+
);
493+
return $cv;
482494
}
483495

484496
__PACKAGE__->meta->make_immutable;

0 commit comments

Comments
 (0)