Skip to content

Commit c3aa447

Browse files
committed
Bulk commit various permission indexing changes.
1 parent 15b3c0b commit c3aa447

File tree

12 files changed

+138
-82
lines changed

12 files changed

+138
-82
lines changed

.tidyallrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ ignore = lib/MetaCPAN/Server/View/JSON.pm
5757
ignore = lib/MetaCPAN/Server/View/Pod.pm
5858
ignore = lib/MetaCPAN/Util.pm
5959
ignore = lib/Plack/Session/Store/ElasticSearch.pm
60+
61+
[SortLines]
62+
select = .gitignore
63+
64+
[UniqueLines]
65+
select = .gitignore

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ env:
2525
- USE_CPANFILE_SNAPSHOT=true
2626
- USE_CPANFILE_SNAPSHOT=false
2727

28+
matrix:
29+
allow_failures:
30+
- env: USE_CPANFILE_SNAPSHOT=false
2831

2932
before_install:
3033
- sudo service elasticsearch stop && curl -O -L https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.4.3.deb && sudo dpkg -i --force-confnew elasticsearch-2.4.3.deb && sudo service elasticsearch start

lib/MetaCPAN/Document/Permission.pm

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
package MetaCPAN::Document::Permission;
22

3-
use strict;
4-
use warnings;
5-
6-
use Moose;
3+
use MetaCPAN::Moose;
74

85
use ElasticSearchX::Model::Document;
9-
use MooseX::StrictConstructor;
6+
use MetaCPAN::Types qw( ArrayRef Str );
107

11-
has module => (
8+
has module_name => (
129
is => 'ro',
13-
isa => 'Str',
10+
isa => Str,
1411
required => 1,
1512
);
1613

1714
has owner => (
18-
is => 'ro',
19-
isa => 'Str',
20-
required => 0,
15+
is => 'ro',
16+
isa => Str,
2117
);
2218

2319
has co_maintainers => (
24-
is => 'ro',
25-
isa => 'ArrayRef',
26-
required => 0,
20+
is => 'ro',
21+
isa => ArrayRef,
2722
);
2823

2924
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Model.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package MetaCPAN::Model;
22

3-
use strict;
4-
use warnings;
5-
63
# load order important
74
use Moose;
5+
86
use ElasticSearchX::Model;
97

108
analyzer lowercase => (

lib/MetaCPAN/Role/Script.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,6 @@ __END__
201201
202202
=head1 SYNOPSIS
203203
204-
Roles which should be available to all modules
204+
Roles which should be available to all modules.
205205
206206
=cut

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package MetaCPAN::Script::Mapping;
22

3-
use strict;
4-
use warnings;
3+
use Moose;
54

5+
use Cpanel::JSON::XS qw( decode_json );
6+
use DateTime ();
7+
use IO::Interactive qw( is_interactive );
8+
use IO::Prompt qw( prompt );
69
use Log::Contextual qw( :log );
7-
use Moose;
10+
use MetaCPAN::Script::Mapping::CPAN::Author ();
11+
use MetaCPAN::Script::Mapping::CPAN::Distribution ();
12+
use MetaCPAN::Script::Mapping::CPAN::Favorite ();
13+
use MetaCPAN::Script::Mapping::CPAN::File ();
14+
use MetaCPAN::Script::Mapping::CPAN::Mirror ();
15+
use MetaCPAN::Script::Mapping::CPAN::Rating ();
16+
use MetaCPAN::Script::Mapping::CPAN::Release ();
17+
use MetaCPAN::Script::Mapping::DeployStatement ();
18+
use MetaCPAN::Script::Mapping::User::Account ();
19+
use MetaCPAN::Script::Mapping::User::Identity ();
20+
use MetaCPAN::Script::Mapping::User::Session ();
821
use MetaCPAN::Types qw( Bool Str );
9-
use Cpanel::JSON::XS qw( decode_json );
10-
use DateTime;
11-
12-
use MetaCPAN::Script::Mapping::DeployStatement;
13-
use MetaCPAN::Script::Mapping::CPAN::Author;
14-
use MetaCPAN::Script::Mapping::CPAN::Distribution;
15-
use MetaCPAN::Script::Mapping::CPAN::Favorite;
16-
use MetaCPAN::Script::Mapping::CPAN::File;
17-
use MetaCPAN::Script::Mapping::CPAN::Mirror;
18-
use MetaCPAN::Script::Mapping::CPAN::Rating;
19-
use MetaCPAN::Script::Mapping::CPAN::Release;
20-
use MetaCPAN::Script::Mapping::User::Account;
21-
use MetaCPAN::Script::Mapping::User::Identity;
22-
use MetaCPAN::Script::Mapping::User::Session;
2322

2423
use constant {
2524
EXPECTED => 1,

lib/MetaCPAN/Script/Permission.pm

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package MetaCPAN::Script::Permission;
22

3-
use strict;
4-
use warnings;
5-
63
use Moose;
7-
with 'MooseX::Getopt', 'MetaCPAN::Role::Script';
84

95
use Log::Contextual qw( :log );
10-
use PAUSE::Permissions;
6+
use MetaCPAN::Document::Permission ();
7+
use PAUSE::Permissions ();
118

12-
use MetaCPAN::Document::Permission;
9+
with 'MooseX::Getopt', 'MetaCPAN::Role::Script';
1310

1411
=head1 SYNOPSIS
1512
@@ -27,23 +24,42 @@ sub run {
2724
sub index_permissions {
2825
my $self = shift;
2926

30-
my $file_path = $self->cpan . '/modules/06perms.txt';
31-
my $pp = PAUSE::Permissions->new( path => $file_path );
32-
my $type = $self->index->type('permission');
33-
my $bulk = $self->model->bulk( size => 100 );
34-
35-
my $iterator = $pp->module_iterator();
36-
while ( my $mp = $iterator->next_module ) {
37-
my $put = { module => $mp->name };
38-
$put->{owner} = $mp->owner if $mp->owner;
39-
$put->{co_maintainers} = $mp->co_maintainers if $mp->co_maintainers;
40-
$bulk->put( $type->new_document($put) );
27+
my $file_path
28+
= $self->cpan->subdir('modules')->file('06perms.txt')->absolute;
29+
my $pp = PAUSE::Permissions->new( path => $file_path );
30+
31+
my $bulk_helper = $self->es->bulk_helper(
32+
index => $self->index->name,
33+
type => 'permission',
34+
);
35+
36+
my $iterator = $pp->module_iterator;
37+
while ( my $perms = $iterator->next_module ) {
38+
39+
# This method does a "return sort @foo", so it can't be called in the
40+
# ternary since it always returns false in that context.
41+
# https://github.com/neilb/PAUSE-Permissions/pull/16
42+
43+
my @co_maints = $perms->co_maintainers;
44+
my $doc = {
45+
@co_maints
46+
? ( co_maintainers => \@co_maints )
47+
: (),
48+
module_name => $perms->name,
49+
owner => $perms->owner,
50+
};
51+
52+
$bulk_helper->update(
53+
{
54+
id => $perms->name,
55+
doc => $doc,
56+
doc_as_upsert => 1,
57+
}
58+
);
4159
}
4260

43-
$bulk->commit;
44-
45-
$self->index->refresh;
46-
log_info {'done'};
61+
$bulk_helper->flush;
62+
log_info {'finished indexing 06perms'};
4763
}
4864

4965
__PACKAGE__->meta->make_immutable;
@@ -61,6 +77,6 @@ Parse out CPAN author permissions.
6177
=head2 index_authors
6278
6379
Adds/updates all ownership and maintenance permissions in the CPAN index to
64-
ElasticSearch.
80+
Elasticsearch.
6581
6682
=cut

lib/MetaCPAN/Server/Controller/Permission.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package MetaCPAN::Server::Controller::Permission;
22

3-
use strict;
4-
use warnings;
5-
use namespace::autoclean;
6-
73
use Moose;
4+
use namespace::autoclean;
85

96
BEGIN { extends 'MetaCPAN::Server::Controller' }
107

t/00_setup.t

100644100755
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ use lib 't/lib';
55

66
use CPAN::Faker 0.010;
77
use Devel::Confess;
8-
use File::Copy;
9-
use MetaCPAN::Script::Tickets;
8+
use File::Copy qw( copy );
9+
use MetaCPAN::Script::Tickets ();
1010
use MetaCPAN::Server::Test;
1111
use MetaCPAN::TestHelpers qw(
1212
fakecpan_configs_dir
1313
fakecpan_dir
1414
get_config
1515
tmp_dir
1616
);
17-
use MetaCPAN::TestServer;
17+
use MetaCPAN::TestServer ();
1818
use Module::Faker 0.015 (); # Generates META.json.
19-
use Path::Class qw(dir);
2019
use Path::Class qw(dir file);
2120
use Test::More 0.96;
22-
use Test::More 0.96 ();
23-
use Test::Most;
21+
use URI::FromHash qw( uri );
2422

2523
# Ensure we're starting fresh
2624
my $tmp_dir = tmp_dir();
@@ -55,7 +53,7 @@ my $cpan = CPAN::Faker->new(
5553
ok( $cpan->make_cpan, 'make fake cpan' );
5654
$fakecpan_dir->subdir('authors')->mkpath;
5755

58-
# do some changes to 06perms.txt
56+
# make some changes to 06perms.txt
5957
{
6058
my $perms_file = $fakecpan_dir->subdir('modules')->file('06perms.txt');
6159
my $perms = $perms_file->slurp;
@@ -79,6 +77,7 @@ copy( $src_dir->file('author-1.0.json'),
7977

8078
copy( $src_dir->file('bugs.tsv'), $fakecpan_dir->file('bugs.tsv') );
8179

80+
$server->index_permissions;
8281
$server->index_releases;
8382
$server->set_latest;
8483
$server->set_first;
@@ -89,12 +88,15 @@ $server->index_cpantesters;
8988
ok(
9089
MetaCPAN::Script::Tickets->new_with_options(
9190
{
92-
%{$config},
93-
rt_summary_url => 'file://'
94-
. $fakecpan_dir->file('bugs.tsv')->absolute,
95-
github_issues => 'file://'
96-
. $fakecpan_dir->subdir('github')->absolute
97-
. '/%s/%s.json?per_page=100',
91+
rt_summary_url => uri(
92+
scheme => 'file',
93+
path => $fakecpan_dir->file('bugs.tsv')->absolute->stringify,
94+
),
95+
github_issues => uri(
96+
scheme => 'file',
97+
path => $fakecpan_dir->subdir('github')->absolute->stringify
98+
. '/%s/%s.json?per_page=100'
99+
),
98100
}
99101
)->run,
100102
'tickets'

t/lib/MetaCPAN/Server/Test.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use strict;
44
use warnings;
55

66
use HTTP::Request::Common qw(POST GET DELETE);
7+
use MetaCPAN::Server ();
78
use Plack::Test;
89
use Test::More;
9-
use MetaCPAN::Server;
1010

1111
use base 'Exporter';
1212
our @EXPORT = qw(

t/lib/MetaCPAN/TestServer.pm

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package MetaCPAN::TestServer;
22

33
use MetaCPAN::Moose;
44

5-
use CPAN::Repository::Perms;
6-
use MetaCPAN::Script::Author;
5+
use MetaCPAN::Script::Author ();
76
use MetaCPAN::Script::CPANTesters ();
8-
use MetaCPAN::Script::Latest;
9-
use MetaCPAN::Script::First;
10-
use MetaCPAN::Script::Mapping;
11-
use MetaCPAN::Script::Release;
12-
use MetaCPAN::Server ();
13-
use MetaCPAN::TestHelpers qw( get_config fakecpan_dir );
7+
use MetaCPAN::Script::First ();
8+
use MetaCPAN::Script::Latest ();
9+
use MetaCPAN::Script::Mapping ();
10+
use MetaCPAN::Script::Permission ();
11+
use MetaCPAN::Script::Release ();
12+
use MetaCPAN::Server ();
13+
use MetaCPAN::TestHelpers qw( fakecpan_dir );
1414
use MetaCPAN::Types qw( Dir HashRef Str );
1515
use Search::Elasticsearch;
1616
use Search::Elasticsearch::TestServer;
@@ -214,6 +214,15 @@ sub index_cpantesters {
214214
);
215215
}
216216

217+
sub index_permissions {
218+
my $self = shift;
219+
220+
ok(
221+
MetaCPAN::Script::Permission->new_with_options( $self->_config )->run,
222+
'index permissions'
223+
);
224+
}
225+
217226
sub prepare_user_test_data {
218227
my $self = shift;
219228
ok(

t/server/controller/permission.t

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use strict;
2+
use warnings;
3+
4+
use Cpanel::JSON::XS qw( decode_json );
5+
use MetaCPAN::Server::Test;
6+
use MetaCPAN::TestServer;
7+
use Test::More;
8+
9+
my $server = MetaCPAN::TestServer->new;
10+
$server->index_permissions;
11+
12+
test_psgi app, sub {
13+
my $cb = shift;
14+
15+
my $module_name = 'CPAN::Test::Dummy::Perl5::VersionBump::Undef';
16+
ok( my $res = $cb->( GET "/permission/$module_name" ),
17+
"GET $module_name" );
18+
is( $res->code, 200, '200 OK' );
19+
20+
is_deeply(
21+
decode_json( $res->content ),
22+
{
23+
co_maintainers => ['FOOBAR'],
24+
module_name => $module_name,
25+
owner => 'MIYAGAWA',
26+
},
27+
'Owned by MIYAGAWA'
28+
);
29+
};
30+
31+
done_testing;

0 commit comments

Comments
 (0)