Skip to content

Commit

Permalink
Merge pull request #672 from metacpan/mickey/scripts_updating_distrib…
Browse files Browse the repository at this point in the history
…ution_type

Fix type updates in distribution
  • Loading branch information
oalders committed May 30, 2017
2 parents 71c4524 + 5c76efc commit 8259336
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
11 changes: 3 additions & 8 deletions lib/MetaCPAN/Script/External.pm
Expand Up @@ -76,6 +76,7 @@ sub update {

while ( my $s = $scroll->next ) {
my $name = $s->{_source}{name};
next unless $name;

if ( exists $dist->{$name} ) {
delete $dist->{$name}
Expand All @@ -93,13 +94,6 @@ sub update {
);

for my $d ( keys %{$dist} ) {
my $exists = $self->es->exists(
index => $self->index->name,
type => 'distribution',
id => $d,
);
next unless $exists;

log_debug {"[$external_source] adding $d"};
$bulk->update(
{
Expand All @@ -108,7 +102,8 @@ sub update {
'external_package' => {
$external_source => $dist->{$d}
}
}
},
doc_as_upsert => 1,
}
);
}
Expand Down
28 changes: 19 additions & 9 deletions lib/MetaCPAN/Script/River.pm
Expand Up @@ -27,17 +27,27 @@ sub run {

sub index_river_summaries {
my ( $self, $summaries ) = @_;
$self->index->refresh;
my $dists = $self->index->type('distribution');
my $bulk = $self->index->bulk( size => 300 );
for my $summary (@$summaries) {

my $bulk = $self->es->bulk_helper(
index => $self->index->name,
type => 'distribution',
);

for my $summary ( @{$summaries} ) {
my $dist = delete $summary->{dist};
my $doc = $dists->get($dist);
$doc ||= $dists->new_document( { name => $dist } );
$doc->_set_river($summary);
$bulk->put($doc);

$bulk->update(
{
id => $dist,
doc => {
name => $dist,
river => $summary,
},
doc_as_upsert => 1,
}
);
}
$bulk->commit;
$bulk->flush;
}

sub retrieve_river_summaries {
Expand Down

0 comments on commit 8259336

Please sign in to comment.