Skip to content

Commit

Permalink
Merge pull request #1312 from metacpan/haarg/speed-up-contribs
Browse files Browse the repository at this point in the history
contributors: fetch all contrib pauseids in one query
  • Loading branch information
haarg authored Nov 4, 2024
2 parents fcd2c46 + a9b7b2f commit d07acb3
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/MetaCPAN/Query/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ sub get_contributors {
$dupe ? () : $info;
} ( @$authors, @$contribs );

my %want_email;
for my $contrib (@contribs) {

# heuristic to autofill pause accounts
Expand All @@ -165,20 +166,27 @@ sub get_contributors {

}

# check if contributor's email points to a registered author
if ( !$contrib->{pauseid} ) {
for my $email ( @{ $contrib->{email} } ) {
my $check_author = $self->es->search(
es_doc_path('author'),
body => {
query => { term => { email => $email } },
size => 10,
}
);
push @{ $want_email{$_} }, $contrib for @{ $contrib->{email} };
}

if (%want_email) {
my $check_author = $self->es->search(
es_doc_path('author'),
body => {
query => { terms => { email => [ sort keys %want_email ] } },
_source => [ 'email', 'pauseid' ],
size => 100,
},
);

if ( hit_total($check_author) ) {
$contrib->{pauseid}
= uc $check_author->{hits}{hits}[0]{_source}{pauseid};
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;
}
}
}
Expand Down

0 comments on commit d07acb3

Please sign in to comment.