|
1 | 1 | package MetaCPAN::Query::Release;
|
| 2 | +use v5.20; |
2 | 3 |
|
3 | 4 | use MetaCPAN::Moose;
|
4 | 5 |
|
@@ -63,158 +64,25 @@ sub aggregate_status_by_author {
|
63 | 64 | sub get_contributors {
|
64 | 65 | my ( $self, $author_name, $release_name ) = @_;
|
65 | 66 |
|
66 |
| - my $query = +{ |
67 |
| - bool => { |
68 |
| - must => [ |
69 |
| - { term => { name => $release_name } }, |
70 |
| - { term => { author => $author_name } }, |
71 |
| - ], |
72 |
| - }, |
73 |
| - }; |
74 |
| - |
75 | 67 | my $res = $self->es->search(
|
76 |
| - es_doc_path('release'), |
| 68 | + es_doc_path('contributor'), |
77 | 69 | body => {
|
78 |
| - query => $query, |
79 |
| - size => 999, |
80 |
| - _source => [qw< metadata.author metadata.x_contributors >], |
81 |
| - } |
82 |
| - ); |
83 |
| - |
84 |
| - my $release = $res->{hits}{hits}[0]{_source}; |
85 |
| - my $contribs = $release->{metadata}{x_contributors} || []; |
86 |
| - my $authors = $release->{metadata}{author} || []; |
87 |
| - |
88 |
| - for ( \( $contribs, $authors ) ) { |
89 |
| - |
90 |
| - # If a sole contributor is a string upgrade it to an array... |
91 |
| - $$_ = [$$_] |
92 |
| - if !ref $$_; |
93 |
| - |
94 |
| - # but if it's any other kind of value don't die trying to parse it. |
95 |
| - $$_ = [] |
96 |
| - unless Ref::Util::is_arrayref($$_); |
97 |
| - } |
98 |
| - $authors = [ grep { $_ ne 'unknown' } @$authors ]; |
99 |
| - |
100 |
| - # this check is against a failure in tests (because fake author) |
101 |
| - return |
102 |
| - unless $self->es->exists( es_doc_path('author'), id => $author_name, |
103 |
| - ); |
104 |
| - |
105 |
| - my $author = $self->es->get( es_doc_path('author'), id => $author_name, ); |
106 |
| - |
107 |
| - my $author_email = $author->{_source}{email}; |
108 |
| - my $author_gravatar_url = $author->{_source}{gravatar_url}; |
109 |
| - |
110 |
| - my $author_info = { |
111 |
| - email => [ |
112 |
| - lc "$author_name\@cpan.org", |
113 |
| - ( |
114 |
| - Ref::Util::is_arrayref($author_email) ? @{$author_email} |
115 |
| - : $author_email |
116 |
| - ), |
117 |
| - ], |
118 |
| - name => $author_name, |
119 |
| - ( |
120 |
| - $author_gravatar_url ? ( gravatar_url => $author_gravatar_url ) |
121 |
| - : () |
122 |
| - ), |
123 |
| - }; |
124 |
| - my %seen = map { $_ => $author_info } |
125 |
| - ( @{ $author_info->{email} }, $author_info->{name}, ); |
126 |
| - |
127 |
| - my @contribs = map { |
128 |
| - my $name = $_; |
129 |
| - my $email; |
130 |
| - if ( $name =~ s/\s*<([^<>]+@[^<>]+)>// ) { |
131 |
| - $email = $1; |
132 |
| - } |
133 |
| - my $info; |
134 |
| - my $dupe; |
135 |
| - if ( $email and $info = $seen{$email} ) { |
136 |
| - $dupe = 1; |
137 |
| - } |
138 |
| - elsif ( $info = $seen{$name} ) { |
139 |
| - $dupe = 1; |
140 |
| - } |
141 |
| - else { |
142 |
| - $info = { |
143 |
| - name => $name, |
144 |
| - email => [], |
145 |
| - }; |
146 |
| - } |
147 |
| - $seen{$name} ||= $info; |
148 |
| - if ($email) { |
149 |
| - push @{ $info->{email} }, $email |
150 |
| - unless grep { $_ eq $email } @{ $info->{email} }; |
151 |
| - $seen{$email} ||= $info; |
152 |
| - } |
153 |
| - $dupe ? () : $info; |
154 |
| - } ( @$authors, @$contribs ); |
155 |
| - |
156 |
| - my %want_email; |
157 |
| - for my $contrib (@contribs) { |
158 |
| - |
159 |
| - # heuristic to autofill pause accounts |
160 |
| - if ( !$contrib->{pauseid} ) { |
161 |
| - my ($pauseid) |
162 |
| - = map { /^(.*)\@cpan\.org$/ ? $1 : () } |
163 |
| - @{ $contrib->{email} }; |
164 |
| - $contrib->{pauseid} = uc $pauseid |
165 |
| - if $pauseid; |
166 |
| - |
167 |
| - } |
168 |
| - |
169 |
| - push @{ $want_email{$_} }, $contrib for @{ $contrib->{email} }; |
170 |
| - } |
171 |
| - |
172 |
| - if (%want_email) { |
173 |
| - my $check_author = $self->es->search( |
174 |
| - es_doc_path('author'), |
175 |
| - body => { |
176 |
| - query => { terms => { email => [ sort keys %want_email ] } }, |
177 |
| - _source => [ 'email', 'pauseid' ], |
178 |
| - size => 100, |
| 70 | + query => { |
| 71 | + bool => { |
| 72 | + must => [ |
| 73 | + { term => { release_name => $release_name } }, |
| 74 | + { term => { release_author => $author_name } }, |
| 75 | + ], |
| 76 | + }, |
179 | 77 | },
|
180 |
| - ); |
181 |
| - |
182 |
| - for my $author ( @{ $check_author->{hits}{hits} } ) { |
183 |
| - my $emails = $author->{_source}{email}; |
184 |
| - $emails = [$emails] |
185 |
| - if !ref $emails; |
186 |
| - my $pauseid = uc $author->{_source}{pauseid}; |
187 |
| - for my $email (@$emails) { |
188 |
| - for my $contrib ( @{ $want_email{$email} } ) { |
189 |
| - $contrib->{pauseid} = $pauseid; |
190 |
| - } |
191 |
| - } |
192 |
| - } |
193 |
| - } |
194 |
| - |
195 |
| - my $contrib_query = +{ |
196 |
| - terms => { |
197 |
| - pauseid => |
198 |
| - [ map { $_->{pauseid} ? $_->{pauseid} : () } @contribs ] |
199 |
| - } |
200 |
| - }; |
201 |
| - |
202 |
| - my $contrib_authors = $self->es->search( |
203 |
| - es_doc_path('author'), |
204 |
| - body => { |
205 |
| - query => $contrib_query, |
206 | 78 | size => 999,
|
207 |
| - _source => [qw< pauseid gravatar_url >], |
| 79 | + _source => [qw< email name pauseid >], |
208 | 80 | }
|
209 | 81 | );
|
210 | 82 |
|
211 |
| - my %id2url = map { $_->{_source}{pauseid} => $_->{_source}{gravatar_url} } |
212 |
| - @{ $contrib_authors->{hits}{hits} }; |
213 |
| - for my $contrib (@contribs) { |
214 |
| - next unless $contrib->{pauseid}; |
215 |
| - $contrib->{gravatar_url} = $id2url{ $contrib->{pauseid} } |
216 |
| - if exists $id2url{ $contrib->{pauseid} }; |
217 |
| - } |
| 83 | + my @contribs = map $_->{_source}, @{ $res->{hits}{hits} }; |
| 84 | + |
| 85 | + @contribs = sort { fc $a->{name} cmp fc $b->{name} } @contribs; |
218 | 86 |
|
219 | 87 | return { contributors => \@contribs };
|
220 | 88 | }
|
|
0 commit comments