From 56a1bb09264bf991d10cf4fd1cfa0c6436f11725 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 30 Apr 2024 18:14:30 +0200 Subject: [PATCH] drop support for metacpan_script 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. --- lib/MetaCPAN/Server/QuerySanitizer.pm | 8 ---- t/server/sanitize_query.t | 54 --------------------------- 2 files changed, 62 deletions(-) diff --git a/lib/MetaCPAN/Server/QuerySanitizer.pm b/lib/MetaCPAN/Server/QuerySanitizer.pm index e54adedb2..bacee3a6c 100644 --- a/lib/MetaCPAN/Server/QuerySanitizer.pm +++ b/lib/MetaCPAN/Server/QuerySanitizer.pm @@ -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) { diff --git a/t/server/sanitize_query.t b/t/server/sanitize_query.t index f4b9ae6eb..2358aae56 100644 --- a/t/server/sanitize_query.t +++ b/t/server/sanitize_query.t @@ -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 { @@ -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' } } }