Skip to content

Commit 2a7a80b

Browse files
authored
Merge pull request #1296 from metacpan/haarg/esconfig
ESConfig: configurable Elasticsearch document types to allow splitting index
2 parents 6974280 + d6571ec commit 2a7a80b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+979
-957
lines changed

.perlcriticrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ theme = core
1616
[-ValuesAndExpressions::ProhibitNoisyQuotes]
1717
[-Variables::ProhibitPunctuationVars]
1818

19+
# doesn't understand signatures
20+
[-Subroutines::ProhibitSubroutinePrototypes]
21+
1922
[CodeLayout::RequireTrailingCommas]
2023
severity = 4
2124

lib/Catalyst/Plugin/Session/Store/ElasticSearch.pm

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use Moose;
66
extends 'Catalyst::Plugin::Session::Store';
77
use MooseX::Types::ElasticSearch qw( ES );
88

9+
use MetaCPAN::ESConfig qw( es_doc_path );
910
use MetaCPAN::Server::Config ();
1011
use MetaCPAN::Util qw( true false );
1112

@@ -17,26 +18,12 @@ has _session_es => (
1718
default =>
1819
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
1920
);
20-
has _session_es_index => (
21-
required => 1,
22-
is => 'ro',
23-
default => sub { shift->_session_plugin_config->{index} || 'user' }
24-
);
25-
has _session_es_type => (
26-
required => 1,
27-
is => 'ro',
28-
default => sub { shift->_session_plugin_config->{type} || 'session' }
29-
);
3021

3122
sub get_session_data {
3223
my ( $self, $key ) = @_;
3324
if ( my ($sid) = $key =~ /^\w+:(.*)/ ) {
3425
my $data = eval {
35-
$self->_session_es->get(
36-
index => $self->_session_es_index,
37-
type => $self->_session_es_type,
38-
id => $sid,
39-
);
26+
$self->_session_es->get( es_doc_path('session'), id => $sid, );
4027
} || return undef;
4128
if ( $key =~ /^expires:/ ) {
4229
return $data->{_source}->{_expires};
@@ -52,8 +39,7 @@ sub store_session_data {
5239
if ( my ($sid) = $key =~ /^session:(.*)/ ) {
5340
$session->{_expires} = $self->session_expires;
5441
$self->_session_es->index(
55-
index => $self->_session_es_index,
56-
type => $self->_session_es_type,
42+
es_doc_path('session'),
5743
id => $sid,
5844
body => $session,
5945
refresh => true,
@@ -66,8 +52,7 @@ sub delete_session_data {
6652
if ( my ($sid) = $key =~ /^session:(.*)/ ) {
6753
eval {
6854
$self->_session_es->delete(
69-
index => $self->_session_es_index,
70-
type => $self->_session_es_type,
55+
es_doc_path('session'),
7156
id => $sid,
7257
refresh => true,
7358
);
@@ -93,8 +78,6 @@ sub delete_expired_sessions { }
9378
MyApp->config(
9479
'Plugin::Session' => {
9580
servers => ':9200',
96-
index => 'user',
97-
type => 'session',
9881
} );
9982
10083
=head1 DESCRIPTION

lib/MetaCPAN/API/Model/Cover.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package MetaCPAN::API::Model::Cover;
22

3+
use MetaCPAN::ESConfig qw( es_doc_path );
34
use MetaCPAN::Moose;
45

56
use MetaCPAN::Util qw(hit_total);
@@ -12,9 +13,8 @@ sub find_release_coverage {
1213
my $query = +{ term => { release => $release } };
1314

1415
my $res = $self->_run_query(
15-
index => 'cover',
16-
type => 'cover',
17-
body => {
16+
es_doc_path('cover'),
17+
body => {
1818
query => $query,
1919
size => 999,
2020
}

lib/MetaCPAN/API/Model/User.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package MetaCPAN::API::Model::User;
22

3+
use MetaCPAN::ESConfig qw( es_doc_path );
34
use MetaCPAN::Moose;
45

56
with 'MetaCPAN::API::Model::Role::ES';
@@ -17,8 +18,7 @@ sub lookup {
1718
};
1819

1920
my $res = $self->_run_query(
20-
index => 'user',
21-
type => 'account',
21+
es_doc_path('account'),
2222
body => { query => $query },
2323
search_type => 'dfs_query_then_fetch',
2424
);

lib/MetaCPAN/API/Plugin/Model.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ has download => sub {
2121

2222
has search => sub {
2323
my $self = shift;
24-
return MetaCPAN::Query::Search->new(
25-
es => $self->app->es,
26-
index_name => 'cpan',
27-
);
24+
return MetaCPAN::Query::Search->new( es => $self->app->es, );
2825
};
2926

3027
has user => sub {

lib/MetaCPAN/Document/Author.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use ElasticSearchX::Model::Document::Types qw( Location );
77
use ElasticSearchX::Model::Document;
88

99
# load order not important
10-
use Gravatar::URL ();
11-
use MetaCPAN::Types qw( ESBool Profile );
12-
use MetaCPAN::Types::TypeTiny qw(
10+
use Gravatar::URL ();
11+
use MetaCPAN::Document::Author::Profile ();
12+
use MetaCPAN::Types qw( ESBool Profile );
13+
use MetaCPAN::Types::TypeTiny qw(
1314
ArrayRef
1415
ArrayRefPromote
1516
Blog

lib/MetaCPAN/Document/Author/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ has query_author => (
1616

1717
sub _build_query_author {
1818
my $self = shift;
19-
return MetaCPAN::Query::Author->new(
20-
es => $self->es,
21-
index_name => $self->index->name,
22-
);
19+
return MetaCPAN::Query::Author->new( es => $self->es );
2320
}
2421

2522
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/CVE/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ has query_cve => (
2020

2121
sub _build_query_cve {
2222
my $self = shift;
23-
return MetaCPAN::Query::CVE->new(
24-
es => $self->es,
25-
index_name => 'cve',
26-
);
23+
return MetaCPAN::Query::CVE->new( es => $self->es );
2724
}
2825

2926
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/Contributor/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ has query_contributor => (
1616

1717
sub _build_query_contributor {
1818
my $self = shift;
19-
return MetaCPAN::Query::Contributor->new(
20-
es => $self->es,
21-
index_name => 'contributor',
22-
);
19+
return MetaCPAN::Query::Contributor->new( es => $self->es );
2320
}
2421

2522
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/Cover/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ has query_cover => (
1616

1717
sub _build_query_cover {
1818
my $self = shift;
19-
return MetaCPAN::Query::Cover->new(
20-
es => $self->es,
21-
index_name => 'cover',
22-
);
19+
return MetaCPAN::Query::Cover->new( es => $self->es );
2320
}
2421

2522
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/Distribution.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ has river => (
4040

4141
sub releases {
4242
my $self = shift;
43-
return $self->index->type("release")
43+
return $self->index->model->doc("release")
4444
->query( { term => { "distribution" => $self->name } } );
4545
}
4646

lib/MetaCPAN/Document/Distribution/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ has query_distribution => (
1616

1717
sub _build_query_distribution {
1818
my $self = shift;
19-
return MetaCPAN::Query::Distribution->new(
20-
es => $self->es,
21-
index_name => 'cpan',
22-
);
19+
return MetaCPAN::Query::Distribution->new( es => $self->es );
2320
}
2421

2522
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/Favorite/Set.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ has query_favorite => (
2020

2121
sub _build_query_favorite {
2222
my $self = shift;
23-
return MetaCPAN::Query::Favorite->new(
24-
es => $self->es,
25-
index_name => $self->index->name,
26-
);
23+
return MetaCPAN::Query::Favorite->new( es => $self->es );
2724
}
2825

2926
__PACKAGE__->meta->make_immutable;

0 commit comments

Comments
 (0)