Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use /author/by_user endpoint instead of ES query
  • Loading branch information
mickeyn committed Sep 28, 2016
1 parent 01cab45 commit 2f20ea1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
5 changes: 2 additions & 3 deletions lib/MetaCPAN/Web/Controller/Favorite.pm
Expand Up @@ -13,11 +13,10 @@ sub recent : Local : Args(0) {
my @user_ids = map { $_->{user} } @faves;

my $authors
= $c->model('API::Author')->by_user( \@user_ids )->recv->{hits}
->{hits};
= $c->model('API::Author')->by_user( \@user_ids )->recv->{authors};

my %author_for_user_id
= map { $_->{fields}->{user} => $_->{fields}->{pauseid} } @{$authors};
= map { $_->{user} => $_->{pauseid} } @{$authors};

foreach my $fave (@faves) {
if ( exists $author_for_user_id{ $fave->{user} } ) {
Expand Down
14 changes: 3 additions & 11 deletions lib/MetaCPAN/Web/Model/API/Author.pm
Expand Up @@ -94,17 +94,9 @@ sub search {

sub by_user {
my ( $self, $users ) = @_;

my $query = return $self->request(
'/author/_search',
{
query => { match_all => {} },
filter =>
{ or => [ map { { term => { user => $_ } } } @{$users} ] },
fields => [qw(user pauseid)],
size => 100
}
);
return $self->request(
'/author/by_user?fields=user,pauseid&users=' . join ',',
@{$users} );
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit 2f20ea1

Please sign in to comment.