Skip to content

Commit

Permalink
drop support for metacpan_script
Browse files Browse the repository at this point in the history
We no longer need metacpan_script for anything our code uses, and
supporting it complicates our query filtering and interactions with
Elasticsearch.

We've generally been trying to move away from users interacting via
Elasticsearch queries, but if they really need to and need a specific
script, they are always welcome to submit a PR to the API adding what
they need.
  • Loading branch information
haarg committed Apr 30, 2024
1 parent f67d282 commit 56a1bb0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
8 changes: 0 additions & 8 deletions lib/MetaCPAN/Server/QuerySanitizer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ sub _scan_hash_tree {
}
_scan_hash_tree($v) if ref $v;
}
if ( my $mscript = delete $struct->{metacpan_script} ) {
$struct->{script_score} = {
script => {
lang => 'groovy',
file => $mscript
},
};
}
}
elsif ( $ref eq 'ARRAY' ) {
foreach my $item (@$struct) {
Expand Down
54 changes: 0 additions & 54 deletions t/server/sanitize_query.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ test_psgi app, sub {
}
);
}

local
$MetaCPAN::Server::QuerySanitizer::metacpan_scripts{test_script_field}
= q{doc['author.pauseid'].value.length() * 2};

test_all_methods(
{
query => { match_all => {} },
script_fields =>
{ pauselen2 => { metacpan_script => 'test_script_field' }, },
filter => { term => { pauseid => 'RWSTAUNER' } },
},
sub {
my ($req) = shift;

my $res = $cb->($req);
is $res->code, 200, $req->method . ' 200 OK'
or diag explain $res;

my $json = decode_json_ok($res);

is_deeply $json->{hits}{hits}->[0]->{fields},
{ pauselen2 => [18] }, 'script_fields via metacpan_script'
or diag explain $json;
},
);
};

sub test_all_methods {
Expand Down Expand Up @@ -126,34 +100,6 @@ my %replacements = (
stupid_script_that_doesnt_exist => undef,
);

while ( my ( $mscript, $re ) = each %replacements ) {
my $query = filtered_custom_score_hash( metacpan_script => $mscript );

my $sanitizer = MetaCPAN::Server::QuerySanitizer->new( query => $query, );

my $cleaned = $sanitizer->query;
like_if_defined
delete $cleaned->{query}{filtered}{query}{custom_score}{script},
$re, "$mscript script replaced";

is_deeply $cleaned, filtered_custom_score_hash(),
'metacpan_script removed';

# try another hash structure
$query
= {
foo => { bar => [ { metacpan_script => $mscript, other => 'val' } ] }
};

$cleaned
= MetaCPAN::Server::QuerySanitizer->new( query => $query )->query;

like_if_defined delete $cleaned->{foo}{bar}->[0]->{script},
$re, "$mscript script replaced";
is_deeply $cleaned, { foo => { bar => [ { other => 'val' } ] } },
'any hash structure accepts metacpan_script';
}

hash_key_rejected( script => { script => 'foobar' } );
hash_key_rejected(
script => { tree => { of => 'many', hashes => { script => 'foobar' } } }
Expand Down

0 comments on commit 56a1bb0

Please sign in to comment.