Skip to content

Commit 810a462

Browse files
committed
Validate author info is correct format
1 parent a41f506 commit 810a462

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/MetaCPAN/Script/Author.pm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sub index_authors {
5454
} map { $_->{_source} } @{ $dates->{hits}->{hits} }
5555
};
5656

57-
my $bulk = $self->model->bulk( size => 20 );
57+
my $bulk = $self->model->bulk( size => 100 );
5858

5959
while ( my ( $pauseid, $data ) = each %$authors ) {
6060
my ( $name, $email, $homepage, $asciiname )
@@ -85,6 +85,11 @@ sub index_authors {
8585
map { URI->new($_)->canonical }
8686
grep {$_} @{ $put->{website} }
8787
];
88+
89+
# Now check the format we have is actually correct
90+
my @errors = MetaCPAN::Document::Author->validate($put);
91+
next if scalar @errors;
92+
8893
my $author = $type->new_document($put);
8994
$author->gravatar_url; # build gravatar_url
9095

@@ -106,6 +111,7 @@ sub index_authors {
106111
}
107112
}
108113

114+
# Only try put if this is a valid format
109115
$bulk->put($author);
110116
}
111117
$self->index->refresh;
@@ -114,17 +120,23 @@ sub index_authors {
114120

115121
sub author_config {
116122
my ( $self, $pauseid, $dates ) = @_;
123+
117124
my $fallback = $dates->{$pauseid} ? undef : {};
125+
118126
my $dir = $self->cpan->subdir( 'authors',
119127
MetaCPAN::Util::author_dir($pauseid) );
128+
120129
my @files;
121130
opendir( my $dh, $dir ) || return $fallback;
131+
132+
# Get the most recent version
122133
my ($file)
123134
= sort { $dir->file($b)->stat->mtime <=> $dir->file($a)->stat->mtime }
124135
grep {m/author-.*?\.json/} readdir($dh);
125136
return $fallback unless ($file);
126137
$file = $dir->file($file);
127138
return $fallback if !-e $file;
139+
128140
my $mtime = DateTime->from_epoch( epoch => $file->stat->mtime );
129141

130142
if ( $dates->{$pauseid} && $dates->{$pauseid} >= $mtime ) {

0 commit comments

Comments
 (0)