Skip to content

Commit

Permalink
Adds script for setting 'backpan' status without re-indexing.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Oct 24, 2014
1 parent 282d7c3 commit ae0a3e1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/MetaCPAN/Role/Common.pm
Expand Up @@ -126,7 +126,6 @@ sub _build_logger {
}

sub file2mod {

my $self = shift;
my $name = shift;

Expand Down
75 changes: 75 additions & 0 deletions lib/MetaCPAN/Script/Backpan.pm
@@ -0,0 +1,75 @@
package MetaCPAN::Script::Backpan;

use strict;
use warnings;

use BackPAN::Index;
use Moose;

with 'MetaCPAN::Role::Common', 'MooseX::Getopt::Dashes';

sub run {
my $self = shift;

my $backpan = BackPAN::Index->new( debug => 0 );
my $releases = $backpan->releases();

my @search;
while ( my $release = $releases->next ) {
push @search,
{
and => [
{ term => { 'author' => $release->cpanid } },
{ term => { 'name' => $release->distvname } },
{ not => { term => { status => 'backpan' } } },
]
};
if ( scalar @search >= 5000 ) {
$self->update_status(@search);
@search = ();
}
}
$self->update_status(@search) if @search;
}

sub update_status {
my $self = shift;
my @search = @_;

my $es = $self->es;
$es->trace_calls(1) if $ENV{DEBUG};

my $scroll = $es->scrolled_search(
size => 500,
scroll => '2m',
index => 'cpan_v1',
type => 'release',
fields => [ 'author', 'name' ],
query => {
filtered => {
query => { match_all => {} },
filter => {
or => \@search,
},
},
},
);

while ( my $release = $scroll->next ) {
$es->update(
index => 'cpan_v1',
type => 'release',
id => $release->{_id},
doc => { status => 'backpan' }
);
}
}

__PACKAGE__->meta->make_immutable;
1;

=pod
Sets "backpan" status on all BackPAN releases.
=cut

1 comment on commit ae0a3e1

@tsibley
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to set status: backpan on all the files contained within a release.

Please sign in to comment.