From f73e6c10c6c76b897fb1d7067b85f609132fb4a4 Mon Sep 17 00:00:00 2001 From: Mickey Nasriachi Date: Tue, 5 Nov 2024 07:26:27 +0100 Subject: [PATCH] get_contributors: follow api changes --- lib/MetaCPAN/Contributor.pm | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/MetaCPAN/Contributor.pm b/lib/MetaCPAN/Contributor.pm index 63adfef..a10c2d2 100644 --- a/lib/MetaCPAN/Contributor.pm +++ b/lib/MetaCPAN/Contributor.pm @@ -177,6 +177,7 @@ sub get_contributors ( $author_name, $release_name ) { $dupe ? () : $info; } ( @$authors, @$contribs ); + my %want_email; for my $contrib (@contribs) { # heuristic to autofill pause accounts @@ -189,20 +190,26 @@ sub get_contributors ( $author_name, $release_name ) { } - # check if contributor's email points to a registered author - if ( !$contrib->{pauseid} ) { - for my $email ( @{ $contrib->{email} } ) { - my $check_author = $es->search( - type => 'author', - body => { - query => { term => { email => $email } }, - size => 10, - } - ); - - if ( $check_author->{hits}{total} ) { - $contrib->{pauseid} - = uc $check_author->{hits}{hits}[0]{_source}{pauseid}; + push @{ $want_email{$_} }, $contrib for @{ $contrib->{email} }; + } + + if (%want_email) { + my $check_author = $es->search( + type => 'author', + body => { + query => { term => { email => [ sort keys %want_email ] } }, + _source => [ 'email', 'pauseid' ], + size => 10, + } + ); + + for my $author ( @{ $check_author->{hits}{hits} } ) { + my $emails = $author->{_source}{email}; + $emails = [$emails] if !ref $emails; + my $pauseid = uc $author->{_source}{pauseid}; + for my $email (@$emails) { + for my $contrib ( @{ $want_email{$email} } ) { + $contrib->{pauseid} = $pauseid; } } }