Skip to content

Commit

Permalink
Merge branch 'master' into mickey/file_dir_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Jun 2, 2017
2 parents c6329e0 + 0841049 commit c8dd39c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Sitemap.pm
Expand Up @@ -58,7 +58,7 @@ sub process {
# XXX Remove this hardcoded URL
my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => ['api.metacpan.org'],
nodes => ['https://fastapi.metacpan.org'],
send_get_body_as => 'POST',
);

Expand All @@ -67,7 +67,7 @@ sub process {
# Start off with standard search parameters ..

my %search_parameters = (
index => 'v0',
index => 'v1',
size => 5000,
type => $self->object_type,
fields => [$field_name],
Expand Down
21 changes: 4 additions & 17 deletions lib/MetaCPAN/Web/Controller/Favorite.pm
Expand Up @@ -4,29 +4,16 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }

sub recent : Local : Args(0) {
my ( $self, $c ) = @_;

my $page_size = $c->req->get_page_size(100);

my $data = $c->model('API::Favorite')->recent( $c->req->page, $page_size )
->recv;
my @faves = map { $_->{_source} } @{ $data->{hits}->{hits} };
my @user_ids = map { $_->{user} } @faves;

my $authors = $c->model('API::Author')->by_user( \@user_ids );
my %author_for_user_id = map { $_->{user} => $_->{pauseid} } @{$authors};

foreach my $fave (@faves) {
next unless exists $author_for_user_id{ $fave->{user} };
$fave->{clicked_by_author} = $author_for_user_id{ $fave->{user} };
}

my $data
= $c->model('API::Favorite')->recent( $c->req->page, $page_size );
$c->stash(
{
header => 1,
recent => \@faves,
show_clicked_by => 1,
recent => $data->{favorites},
took => $data->{took},
total => $data->{hits}->{total},
total => $data->{total},
page_size => $page_size,
template => 'favorite/recent.html',
}
Expand Down
26 changes: 18 additions & 8 deletions lib/MetaCPAN/Web/Model/API/Favorite.pm
Expand Up @@ -86,15 +86,25 @@ sub by_user {

sub recent {
my ( $self, $page, $page_size ) = @_;
$self->request(
'/favorite/_search',
{
size => $page_size,
from => ( $page - 1 ) * $page_size,
query => { match_all => {} },
sort => [ { 'date' => { order => 'desc' } } ]
my $data = $self->request( '/favorite/recent',
{ size => $page_size, page => $page } )->recv;

my @user_ids = map { $_->{user} } @{ $data->{favorites} };
return $data unless @user_ids;

my $authors
= $self->request( '/author/by_user', undef, { user => \@user_ids } )
->recv;
if ( $authors and exists $authors->{authors} ) {
my %author_for_user_id
= map { $_->{user} => $_->{pauseid} } @{ $authors->{authors} };
for my $fav ( @{ $data->{favorites} } ) {
next unless exists $author_for_user_id{ $fav->{user} };
$fav->{clicked_by_author} = $author_for_user_id{ $fav->{user} };
}
);
}

return $data;
}

sub leaderboard {
Expand Down

0 comments on commit c8dd39c

Please sign in to comment.