Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
switch sesson script to new ES bulk_helper
  • Loading branch information
ranguard committed Apr 22, 2016
1 parent 44fb92d commit 0452ae9
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/MetaCPAN/Script/Session.pm
Expand Up @@ -20,32 +20,24 @@ sub run {
{ query => { filtered => { query => { match_all => {} }, }, }, },
);

my @delete;
my $bulk = $self->es->bulk_helper(
index => 'user',
type => 'session',
max_count => 10_000
);

my $cutoff = DateTime->now->subtract( months => 1 )->epoch;

while ( my $search = $scroll->next ) {
if ( $search->{_source}->{__updated} < $cutoff ) {
push @delete, $search->{_id};
}

if ( scalar @delete >= 10_000 ) {
$self->delete(@delete);
@delete = ();
if ( $search->{_source}->{__updated} < $cutoff ) {
$bulk->delete( { id => $search->{_id} } );
}

}
$self->delete(@delete) if @delete;
}

sub delete {
my $self = shift;
my @delete = @_;
$bulk->flush;

$self->es->bulk(
index => 'user',
type => 'session',
actions => [ map { +{ delete => { id => $_ } } } @delete ],
);
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit 0452ae9

Please sign in to comment.