@@ -25,9 +25,28 @@ sub update_contributors {
25
25
},
26
26
);
27
27
28
- my $bulk = $self -> es-> bulk_helper( es_doc_path(' contributor' ) );
28
+ my $report = sub {
29
+ my ( $action , $result , $i ) = @_ ;
30
+ if ( $i == 0 ) {
31
+ log_info {' flushing contributor updates' };
32
+ }
33
+ };
34
+
35
+ my $bulk = $self -> es-> bulk_helper(
36
+ es_doc_path(' contributor' ),
37
+ on_success => $report ,
38
+ on_error => $report ,
39
+ );
40
+
41
+ log_info { ' updating contributors for ' . $scroll -> total . ' releases' };
29
42
30
43
while ( my $release = $scroll -> next ) {
44
+ my $source = $release -> {_source };
45
+ my $name = $source -> {name };
46
+ if ( !( $name && $source -> {author } && $source -> {distribution } ) ) {
47
+ Dlog_warn {" found broken release: $_ " } $release ;
48
+ next ;
49
+ }
31
50
log_debug { ' updating contributors for ' . $release -> {_source }{name } };
32
51
my $actions = $self -> release_contributor_update_actions(
33
52
$release -> {_source } );
@@ -78,6 +97,11 @@ sub release_contributor_update_actions {
78
97
return \@actions ;
79
98
}
80
99
100
+ has email_mapping => (
101
+ is => ' ro' ,
102
+ default => sub { {} },
103
+ );
104
+
81
105
sub get_contributors {
82
106
my ( $self , $release ) = @_ ;
83
107
@@ -164,24 +188,34 @@ sub get_contributors {
164
188
}
165
189
166
190
if (%want_email ) {
167
- my $check_author = $self -> es-> search(
168
- es_doc_path(' author' ),
169
- body => {
170
- query => { terms => { email => [ sort keys %want_email ] } },
171
- _source => [ ' email' , ' pauseid' ],
172
- size => 100,
173
- },
174
- );
175
-
176
- for my $author ( @{ $check_author -> {hits }{hits } } ) {
177
- my $emails = $author -> {_source }{email };
178
- $emails = [$emails ]
179
- if !ref $emails ;
180
- my $pauseid = uc $author -> {_source }{pauseid };
181
- for my $email (@$emails ) {
182
- for my $contrib ( @{ $want_email {$email } } ) {
183
- $contrib -> {pauseid } = $pauseid ;
184
- }
191
+ my $email_mapping = $self -> email_mapping;
192
+
193
+ my @fetch_email = grep !exists $email_mapping -> {$_ },
194
+ sort keys %want_email ;
195
+
196
+ if (@fetch_email ) {
197
+ my $check_author = $self -> es-> search(
198
+ es_doc_path(' author' ),
199
+ body => {
200
+ query => { terms => { email => \@fetch_email } },
201
+ _source => [ ' email' , ' pauseid' ],
202
+ size => 100,
203
+ },
204
+ );
205
+
206
+ for my $author ( @{ $check_author -> {hits }{hits } } ) {
207
+ my $pauseid = uc $author -> {_source }{pauseid };
208
+ my $emails = $author -> {_source }{email };
209
+ $email_mapping -> {$_ } //= $pauseid
210
+ for ref $emails ? @$emails : $emails ;
211
+ }
212
+ }
213
+
214
+ for my $email ( keys %want_email ) {
215
+ my $pauseid = $email_mapping -> {$email }
216
+ or next ;
217
+ for my $contrib ( @{ $want_email {$email } } ) {
218
+ $contrib -> {pauseid } = $pauseid ;
185
219
}
186
220
}
187
221
}
0 commit comments