Skip to content

Commit

Permalink
script: river: use bulk_helper. do non-destructive updates'
Browse files Browse the repository at this point in the history
currently, the river script overrides the entries in
'distirbution' so data updated by other scripts (tickets/external)
gets scraped (and later re-introduced by those scripts)
  • Loading branch information
mickeyn committed May 30, 2017
1 parent aac7064 commit 5c76efc
Showing 1 changed file with 19 additions and 9 deletions.
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 5c76efc

Please sign in to comment.