Skip to content

Commit 0e55e2e

Browse files
committed
find es index/type via ESConfig rather than passing index around
Many parts of the code treated the index as the parent of all data, so it was the thing being passed around. That will no be true in the future. Instead, ESConfig can give the path (index+type) of each named document type. Convert most places passing around index to use es_doc_path.
1 parent 2f5b7d1 commit 0e55e2e

Some content is hidden

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

41 files changed

+244
-430
lines changed

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/Document/File/Set.pm

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package MetaCPAN::Document::File::Set;
33
use Moose;
44

55
use List::Util qw( max );
6+
use MetaCPAN::ESConfig qw( es_doc_path );
67
use MetaCPAN::Query::Favorite ();
78
use MetaCPAN::Query::File ();
89
use MetaCPAN::Query::Release ();
@@ -123,8 +124,7 @@ sub find {
123124
};
124125

125126
my $res = $self->es->search(
126-
index => $self->index->name,
127-
type => 'file',
127+
es_doc_path('file'),
128128
search_type => 'dfs_query_then_fetch',
129129
body => {
130130
query => $query,
@@ -307,9 +307,8 @@ sub autocomplete {
307307

308308
my $data = $self->es->search(
309309
search_type => 'dfs_query_then_fetch',
310-
index => $self->index->name,
311-
type => 'file',
312-
body => {
310+
es_doc_path('file'),
311+
body => {
313312
query => $query,
314313
sort => [ '_score', 'documentation' ],
315314
_source => [qw( documentation release author distribution )],
@@ -329,8 +328,8 @@ sub autocomplete_suggester {
329328
my $search_size = 100;
330329

331330
my $suggestions = $self->es->suggest( {
332-
index => $self->index->name,
333-
body => {
331+
es_doc_path('file'),
332+
body => {
334333
documentation => {
335334
text => $query,
336335
completion => {
@@ -349,9 +348,8 @@ sub autocomplete_suggester {
349348
}
350349

351350
my $data = $self->es->search( {
352-
index => $self->index->name,
353-
type => 'file',
354-
body => {
351+
es_doc_path('file'),
352+
body => {
355353
query => {
356354
bool => {
357355
must => [

lib/MetaCPAN/Model/Release.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use DateTime ();
1010
use File::Find ();
1111
use File::Spec ();
1212
use Log::Contextual qw( :log :dlog );
13+
use MetaCPAN::ESConfig qw( es_doc_path );
1314
use MetaCPAN::Model::Archive ();
1415
use MetaCPAN::Types::TypeTiny qw( AbsPath ArrayRef Str );
1516
use MetaCPAN::Util qw( fix_version true false );
@@ -225,11 +226,8 @@ sub _build_document {
225226
= $self->model->doc('release')->put( $document, { refresh => true } );
226227

227228
# create distribution if doesn't exist
228-
my $dist_count = $self->es->count(
229-
index => 'cpan',
230-
type => 'distribution',
231-
body => { query => { term => { name => $self->distribution } } },
232-
);
229+
my $dist_count = $self->es->count( es_doc_path('distribution'),
230+
body => { query => { term => { name => $self->distribution } } }, );
233231
if ( !$dist_count->{count} ) {
234232
$self->model->doc('distribution')
235233
->put( { name => $self->distribution }, { create => 1 } );

lib/MetaCPAN/Query/Author.pm

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package MetaCPAN::Query::Author;
22

33
use MetaCPAN::Moose;
44

5-
use MetaCPAN::Util qw(hit_total);
6-
use Ref::Util qw( is_arrayref );
5+
use MetaCPAN::ESConfig qw( es_doc_path );
6+
use MetaCPAN::Util qw(hit_total);
7+
use Ref::Util qw( is_arrayref );
78

89
with 'MetaCPAN::Query::Role::Common';
910

@@ -17,11 +18,7 @@ sub by_ids {
1718
size => scalar @{$ids},
1819
};
1920

20-
my $authors = $self->es->search(
21-
index => $self->index_name,
22-
type => 'author',
23-
body => $body,
24-
);
21+
my $authors = $self->es->search( es_doc_path('author'), body => $body, );
2522

2623
my @authors = map $_->{_source}, @{ $authors->{hits}{hits} };
2724

@@ -37,9 +34,8 @@ sub by_user {
3734
$users = [$users] unless is_arrayref($users);
3835

3936
my $authors = $self->es->search(
40-
index => $self->index_name,
41-
type => 'author',
42-
body => {
37+
es_doc_path('author'),
38+
body => {
4339
query => { terms => { user => $users } },
4440
size => 500,
4541
}
@@ -82,11 +78,7 @@ sub search {
8278
from => $from || 0,
8379
};
8480

85-
my $ret = $self->es->search(
86-
index => $self->index_name,
87-
type => 'author',
88-
body => $body,
89-
);
81+
my $ret = $self->es->search( es_doc_path('author'), body => $body, );
9082

9183
my @authors = map { +{ %{ $_->{_source} }, id => $_->{_id} } }
9284
@{ $ret->{hits}{hits} };
@@ -113,11 +105,7 @@ sub prefix_search {
113105
from => $from,
114106
};
115107

116-
my $ret = $self->es->search(
117-
index => $self->index_name,
118-
type => 'author',
119-
body => $body,
120-
);
108+
my $ret = $self->es->search( es_doc_path('author'), body => $body, );
121109

122110
my @authors = map { +{ %{ $_->{_source} }, id => $_->{_id} } }
123111
@{ $ret->{hits}{hits} };

lib/MetaCPAN/Query/CVE.pm

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package MetaCPAN::Query::CVE;
22

33
use MetaCPAN::Moose;
44

5+
use MetaCPAN::ESConfig qw( es_doc_path );
6+
57
with 'MetaCPAN::Query::Role::Common';
68

79
sub find_cves_by_cpansa {
@@ -10,9 +12,8 @@ sub find_cves_by_cpansa {
1012
my $query = +{ term => { cpansa_id => $cpansa_id } };
1113

1214
my $res = $self->es->search(
13-
index => $self->index_name,
14-
type => 'cve',
15-
body => {
15+
es_doc_path('cve'),
16+
body => {
1617
query => $query,
1718
size => 999,
1819
}
@@ -27,9 +28,8 @@ sub find_cves_by_release {
2728
my $query = +{ match => { releases => "$author/$release" } };
2829

2930
my $res = $self->es->search(
30-
index => $self->index_name,
31-
type => 'cve',
32-
body => {
31+
es_doc_path('cve'),
32+
body => {
3333
query => $query,
3434
size => 999,
3535
}
@@ -49,9 +49,8 @@ sub find_cves_by_dist {
4949
};
5050

5151
my $res = $self->es->search(
52-
index => $self->index_name,
53-
type => 'cve',
54-
body => {
52+
es_doc_path('cve'),
53+
body => {
5554
query => $query,
5655
size => 999,
5756
}

lib/MetaCPAN/Query/Contributor.pm

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

33
use MetaCPAN::Moose;
44

5-
use MetaCPAN::Util qw(hit_total);
5+
use MetaCPAN::ESConfig qw( es_doc_path );
6+
use MetaCPAN::Util qw(hit_total);
67

78
with 'MetaCPAN::Query::Role::Common';
89

@@ -19,9 +20,8 @@ sub find_release_contributors {
1920
};
2021

2122
my $res = $self->es->search(
22-
index => $self->index_name,
23-
type => 'contributor',
24-
body => {
23+
es_doc_path('contributor'),
24+
body => {
2525
query => $query,
2626
size => 999,
2727
}
@@ -38,9 +38,8 @@ sub find_author_contributions {
3838
my $query = +{ term => { pauseid => $pauseid } };
3939

4040
my $res = $self->es->search(
41-
index => $self->index_name,
42-
type => 'contributor',
43-
body => {
41+
es_doc_path('contributor'),
42+
body => {
4443
query => $query,
4544
size => 999,
4645
}

lib/MetaCPAN/Query/Cover.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package MetaCPAN::Query::Cover;
22

33
use MetaCPAN::Moose;
44

5-
use MetaCPAN::Util qw(hit_total);
5+
use MetaCPAN::ESConfig qw( es_doc_path );
6+
use MetaCPAN::Util qw(hit_total);
67

78
with 'MetaCPAN::Query::Role::Common';
89

@@ -12,9 +13,8 @@ sub find_release_coverage {
1213
my $query = +{ term => { release => $release } };
1314

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

lib/MetaCPAN/Query/Distribution.pm

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

33
use MetaCPAN::Moose;
44

5-
use MetaCPAN::Util qw(hit_total);
5+
use MetaCPAN::ESConfig qw( es_doc_path );
6+
use MetaCPAN::Util qw(hit_total);
67

78
with 'MetaCPAN::Query::Role::Common';
89

@@ -16,9 +17,8 @@ sub get_river_data_by_dist {
1617
};
1718

1819
my $res = $self->es->search(
19-
index => $self->index_name,
20-
type => 'distribution',
21-
body => {
20+
es_doc_path('distribution'),
21+
body => {
2222
query => $query,
2323
size => 999,
2424
}
@@ -38,9 +38,8 @@ sub get_river_data_by_dists {
3838
};
3939

4040
my $res = $self->es->search(
41-
index => $self->index_name,
42-
type => 'distribution',
43-
body => {
41+
es_doc_path('distribution'),
42+
body => {
4443
query => $query,
4544
size => 999,
4645
}

0 commit comments

Comments
 (0)