Skip to content

Commit efb4712

Browse files
committed
WIP: Remove EsX::Model dependency
This is WIP, do NOT merge into master !!!
1 parent ecda017 commit efb4712

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

lib/MetaCPAN/Document/Contributor.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package MetaCPAN::Document::Contributor;
22

33
use MetaCPAN::Moose;
44

5-
use ElasticSearchX::Model::Document;
65
use MetaCPAN::Types qw( Str );
76

87
has distribution => (

lib/MetaCPAN/Document/Release/Set.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );
66

77
use MetaCPAN::Query::Release;
88

9-
extends 'ElasticSearchX::Model::Document::Set';
9+
with 'MetaCPAN::Role::ES';
1010

1111
has query_release => (
1212
is => 'ro',
@@ -37,9 +37,10 @@ has query_release => (
3737

3838
sub _build_query_release {
3939
my $self = shift;
40+
4041
return MetaCPAN::Query::Release->new(
4142
es => $self->es,
42-
index_name => $self->index->name,
43+
index_name => 'cpan',
4344
);
4445
}
4546

lib/MetaCPAN/Role/ES.pm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package MetaCPAN::Role::ES;
2+
3+
use Moose::Role;
4+
use MooseX::Types::ElasticSearch qw(:all);
5+
6+
has es => (
7+
is => 'ro',
8+
isa => ES,
9+
lazy => 1,
10+
coerce => 1,
11+
builder => '_build_es',
12+
);
13+
14+
sub _build_es {
15+
return Search::Elasticsearch->new(
16+
client => '2_0::Direct',
17+
( $ENV{ES} ? ( nodes => [ $ENV{ES} ] ) : () ),
18+
);
19+
}
20+
21+
no Moose::Role;
22+
1;

lib/MetaCPAN/Role/Script.pm

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package MetaCPAN::Role::Script;
22

33
use Moose::Role;
44

5-
use ElasticSearchX::Model::Document::Types qw(:all);
65
use FindBin;
76
use Git::Helpers qw( checkout_root );
87
use Log::Contextual qw( :log :dlog );
9-
use MetaCPAN::Model;
108
use MetaCPAN::Types qw(:all);
119
use Mojo::Server;
1210
use Term::ANSIColor qw( colored );
@@ -16,8 +14,10 @@ use File::Path ();
1614

1715
use Carp ();
1816

19-
with( 'MetaCPAN::Role::HasConfig', 'MetaCPAN::Role::Fastly',
20-
'MetaCPAN::Role::Logger' );
17+
with(
18+
'MetaCPAN::Role::HasConfig', 'MetaCPAN::Role::Fastly',
19+
'MetaCPAN::Role::Logger', 'MetaCPAN::Role::ES'
20+
);
2121

2222
has cpan => (
2323
is => 'ro',
@@ -48,21 +48,6 @@ has proxy => (
4848
default => '',
4949
);
5050

51-
has es => (
52-
is => 'ro',
53-
isa => ES,
54-
required => 1,
55-
coerce => 1,
56-
documentation => 'Elasticsearch http connection string',
57-
);
58-
59-
has model => (
60-
is => 'ro',
61-
lazy => 1,
62-
builder => '_build_model',
63-
traits => ['NoGetopt'],
64-
);
65-
6651
has index => (
6752
reader => '_index',
6853
is => 'ro',
@@ -119,7 +104,6 @@ sub BUILDARGS {
119104
unless $ENV{'ES_SCRIPT_INDEX'}
120105
and $args{'index'} eq $ENV{'ES_SCRIPT_INDEX'};
121106
}
122-
123107
return \%args;
124108
}
125109

@@ -133,18 +117,6 @@ sub handle_error {
133117
Carp::croak $error if $self->die_on_error;
134118
}
135119

136-
sub index {
137-
my $self = shift;
138-
return $self->model->index( $self->_index );
139-
}
140-
141-
sub _build_model {
142-
my $self = shift;
143-
144-
# es provided by ElasticSearchX::Model::Role
145-
return MetaCPAN::Model->new( es => $self->es );
146-
}
147-
148120
sub _build_ua {
149121
my $self = shift;
150122
my $ua = LWP::UserAgent->new;

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 => $self->index->name,
87+
index => 'cpan',
8888
type => 'release',
8989
body => { query => $query },
9090
fields => [qw( author distribution name )],

lib/MetaCPAN/Script/Role/Contributor.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ use Moose::Role;
55
use MetaCPAN::Util qw( digest );
66
use Ref::Util qw( is_arrayref );
77

8+
use MetaCPAN::Document::Release::Set;
9+
810
sub get_cpan_author_contributors {
911
my ( $self, $author, $release, $distribution ) = @_;
1012
my @ret;
1113
my $es = $self->es;
1214

13-
my $type = $self->index->type('release');
15+
my $type = MetaCPAN::Document::Release::Set->new();
1416
my $data;
1517
eval {
1618
$data = $type->get_contributors( $author, $release );
@@ -21,7 +23,7 @@ sub get_cpan_author_contributors {
2123
next unless exists $d->{pauseid};
2224

2325
# skip existing records
24-
my $id = digest( $d->{pauseid}, $release );
26+
my $id = digest( $d->{pauseid}, $release );
2527
my $exists = $es->exists(
2628
index => 'contributor',
2729
type => 'contributor',

0 commit comments

Comments
 (0)