Skip to content

Commit bf0b991

Browse files
committed
Use default index name for 'cpan' based types
1 parent ff4e9b0 commit bf0b991

23 files changed

+65
-57
lines changed

lib/MetaCPAN/Role/ES.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package MetaCPAN::Role::ES;
22

33
use Moose::Role;
44
use MooseX::Types::ElasticSearch qw(:all);
5+
use MetaCPAN::Types qw( Str );
56

67
has es => (
78
is => 'ro',
@@ -11,6 +12,12 @@ has es => (
1112
builder => '_build_es',
1213
);
1314

15+
has index_name => (
16+
is => 'ro',
17+
isa => Str,
18+
default => 'cpan',
19+
);
20+
1421
sub _build_es {
1522
return Search::Elasticsearch->new(
1623
client => '2_0::Direct',
@@ -20,6 +27,7 @@ sub _build_es {
2027

2128
sub refresh {
2229
my ( $self, $name ) = @_;
30+
$name //= $self->index_name;
2331
$self->es->indices->refresh( index => $name );
2432
}
2533

lib/MetaCPAN/Script/Author.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sub run {
3333
my $self = shift;
3434

3535
$self->index_authors;
36-
$self->refresh('cpan');
36+
$self->refresh;
3737
}
3838

3939
sub index_authors {
@@ -56,7 +56,7 @@ sub index_authors {
5656
};
5757

5858
my $bulk = $self->es->bulk_helper(
59-
index => 'cpan',
59+
index => $self->index_name,
6060
type => 'author',
6161
max_count => 250,
6262
timeout => '25m',
@@ -135,7 +135,7 @@ sub index_authors {
135135
);
136136
}
137137
$bulk->flush;
138-
$self->refresh('cpan');
138+
$self->refresh;
139139

140140
$self->purge_author_key(@author_ids_to_purge);
141141
$self->perform_purges;

lib/MetaCPAN/Script/Backpan.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sub build_release_status_map {
9191
my $scroll = $self->es->scroll_helper(
9292
size => 500,
9393
scroll => '5m',
94-
index => 'cpan',
94+
index => $self->index_name,
9595
type => 'release',
9696
fields => [ 'author', 'archive', 'name' ],
9797
body => $self->_get_release_query,
@@ -150,7 +150,7 @@ sub update_releases {
150150
log_info {"update_releases"};
151151

152152
$self->_bulk->{release} ||= $self->es->bulk_helper(
153-
index => 'cpan',
153+
index => $self->index_name,
154154
type => 'release',
155155
max_count => 250,
156156
timeout => '5m',
@@ -193,7 +193,7 @@ sub update_files_author {
193193
my $scroll = $self->es->scroll_helper(
194194
size => 500,
195195
scroll => '5m',
196-
index => 'cpan',
196+
index => $self->index_name,
197197
type => 'file',
198198
fields => ['release'],
199199
body => {
@@ -209,7 +209,7 @@ sub update_files_author {
209209
);
210210

211211
$self->_bulk->{file} ||= $self->es->bulk_helper(
212-
index => 'cpan',
212+
index => $self->index_name,
213213
type => 'file',
214214
max_count => 250,
215215
timeout => '5m',

lib/MetaCPAN/Script/Backup.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ sub run {
6262
return $self->run_restore if $self->restore;
6363

6464
my $es = $self->es;
65-
$self->refresh('cpan');
65+
$self->refresh;
6666

6767
my $filename = join( '-',
6868
DateTime->now->strftime('%F'),

lib/MetaCPAN/Script/CPANTesters.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ has _bulk => (
5050
lazy => 1,
5151
default => sub {
5252
$_[0]->es->bulk_helper(
53-
index => 'cpan',
53+
index => $_[0]->index_name,
5454
type => 'release'
5555
);
5656
},
@@ -67,7 +67,7 @@ sub _build_db {
6767
sub run {
6868
my $self = shift;
6969
$self->index_reports;
70-
$self->refresh('cpan');
70+
$self->refresh;
7171
}
7272

7373
sub index_reports {

lib/MetaCPAN/Script/CPANTestersAPI.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ has _bulk => (
3232
lazy => 1,
3333
default => sub {
3434
$_[0]->es->bulk_helper(
35-
index => 'cpan',
35+
index => $self->index_name,
3636
type => 'release',
3737
max_count => 250,
3838
timeout => '30m',
@@ -43,7 +43,7 @@ has _bulk => (
4343
sub run {
4444
my $self = shift;
4545
$self->index_reports;
46-
$self->refresh('cpan');
46+
$self->refresh;
4747
}
4848

4949
sub index_reports {
@@ -61,7 +61,7 @@ sub index_reports {
6161
my $data = decode_json $json;
6262

6363
my $scroll = $es->scroll_helper(
64-
index => 'cpan',
64+
index => $self->index_name,
6565
search_type => 'scan',
6666
size => '500',
6767
type => 'release',

lib/MetaCPAN/Script/Check.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ sub check_modules {
8484

8585
# look up this module in ElasticSearch and see what we have on it
8686
my $results = $es->search(
87-
index => 'cpan',
87+
index => $self->index_name,
8888
type => 'file',
89-
size => 100, # shouldn't get more than this
89+
size => 100, # shouldn't get more than this
9090
fields => [
9191
qw(name release author distribution version authorized indexed maturity date)
9292
],
@@ -104,7 +104,7 @@ sub check_modules {
104104
# now find the first latest releases for these files
105105
foreach my $file (@files) {
106106
my $release_results = $es->search(
107-
index => 'cpan',
107+
index => $self->index_name,
108108
type => 'release',
109109
size => 1,
110110
fields =>
@@ -133,7 +133,7 @@ sub check_modules {
133133
if ( !@releases ) {
134134
foreach my $file (@files) {
135135
my $release_results = $es->search(
136-
index => 'cpan',
136+
index => $self->index_name,
137137
type => 'release',
138138
size => 1,
139139
fields =>

lib/MetaCPAN/Script/Contributor.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ sub run {
8484
my $scroll = $self->es->scroll_helper(
8585
size => 500,
8686
scroll => $timeout,
87-
index => 'cpan',
87+
index => $self->index_name,
8888
type => 'release',
8989
body => { query => $query },
9090
fields => [qw( author distribution name )],

lib/MetaCPAN/Script/Cover.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sub index_cover_data {
5454
for my $version ( keys %{ $data->{$dist} } ) {
5555
my $release = $dist . '-' . $version;
5656
my $rel_check = $self->es->search(
57-
index => 'cpan',
57+
index => $self->index_name,
5858
type => 'release',
5959
size => 0,
6060
body => {

lib/MetaCPAN/Script/External.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ sub update {
6262
my $external_source = $self->external_source;
6363

6464
my $scroll = $self->es->scroll_helper(
65-
index => 'cpan',
65+
index => $self->index_name,
6666
type => 'distribution',
6767
scroll => '10m',
6868
body => {
@@ -89,7 +89,7 @@ sub update {
8989
}
9090

9191
my $bulk = $self->es->bulk_helper(
92-
index => 'cpan',
92+
index => $self->index_name,
9393
type => 'distribution',
9494
);
9595

0 commit comments

Comments
 (0)