Skip to content

Commit

Permalink
updating bulk code for watcher script
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed May 20, 2016
1 parent 4aa8361 commit 6eab0ae
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions lib/MetaCPAN/Script/Watcher.pm
Expand Up @@ -223,42 +223,45 @@ sub reindex_release {
}
);
return if ( $self->dry_run );
my @bulk;

my %bulk_helper;
for (qw/ file release /) {
$bulk_helper{$_} = $self->es->bulk_helper(
index => $self->index->name,
type => $_,
max_count => 100,
);
}

while ( my $row = $scroll->next ) {
my $source = $row->{_source};
push(
@bulk,
{
index => {
index => $self->index->name,
type => 'file',
id => $row->{_id},
$row->{fields}->{_parent}
? ( parent => $row->{fields}->{_parent} )
: (),
data => { %$source, status => 'backpan' }
}
$bulk_helper{type}->index(
id => $row->{_id},
source => {
index => $self->index->name,
type => 'file',
id => $row->{_id},
$row->{fields}->{_parent}
? ( parent => $row->{fields}->{_parent} )
: (),
data => { %$source, status => 'backpan' }
}
);
if ( @bulk > 100 ) {
$self->es->bulk( \@bulk );
@bulk = ();
}
}
push(
@bulk,
{
index => {
index => $self->index->name,
type => 'release',
id => $release->{_id},
data => { %{ $release->{_source} }, status => 'backpan' },
}

$bulk_helper{release}->index(
id => $release->{_id},
source => {
index => $self->index->name,
type => 'release',
id => $release->{_id},
data => { %{ $release->{_source} }, status => 'backpan' },
}
);
$self->es->bulk( \@bulk ) if (@bulk);

for my $bulk ( values %bulk_helper ) {
$bulk->flush;
}
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit 6eab0ae

Please sign in to comment.