Skip to content

Commit

Permalink
cache the email to pauseid mapping
Browse files Browse the repository at this point in the history
Rather than needing a query for every release to find pause IDs, store
the email to pauseid mapping between releases. This should speed up
running the contributor script with --all.
  • Loading branch information
haarg committed Nov 21, 2024
1 parent 12ed9b1 commit bea9c1f
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions lib/MetaCPAN/Script/Role/Contributor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ sub release_contributor_update_actions {
return \@actions;
}

has email_mapping => (
is => 'ro',
default => sub { {} },
);

sub get_contributors {
my ( $self, $release ) = @_;

Expand Down Expand Up @@ -183,24 +188,34 @@ sub get_contributors {
}

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,
},
);

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;
}
my $email_mapping = $self->email_mapping;

my @fetch_email = grep !exists $email_mapping->{$_},
sort keys %want_email;

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

for my $author ( @{ $check_author->{hits}{hits} } ) {
my $pauseid = uc $author->{_source}{pauseid};
my $emails = $author->{_source}{email};
$email_mapping->{$_} //= $pauseid
for ref $emails ? @$emails : $emails;
}
}

for my $email ( keys %want_email ) {
my $pauseid = $email_mapping->{$email}
or next;
for my $contrib ( @{ $want_email{$email} } ) {
$contrib->{pauseid} = $pauseid;
}
}
}
Expand Down

0 comments on commit bea9c1f

Please sign in to comment.