<commit_before>package NTPPool::Control::Graph;
use strict;
use base qw(NTPPool::Control);
use Combust::Constant qw(OK DECLINED);
use Combust::Gearman::Client ();
use NP::Model;

my $gearman = Combust::Gearman::Client->new;

sub render {
    my $self = shift;

    $self->cache_control('s-maxage=1800');

    my ($p, $type) = ($self->request->uri =~ m!^/graph/([^/]+)/(\w+).png!);
    my ($server) = $p && NP::Model->server->find_server($p);
    return 404 unless $server;
    return 404 unless $type and $type =~ m!^(offset|score)$!;

    # we only have one graph type now
    $type = 'offset';
<commit_msg>Redirect duplicate graph requests to the canonical URL<commit_after>package NTPPool::Control::Graph;
use strict;
use base qw(NTPPool::Control);
use Combust::Constant qw(OK DECLINED);
use Combust::Gearman::Client ();
use NP::Model;

my $gearman = Combust::Gearman::Client->new;

sub render {
    my $self = shift;

    $self->cache_control('s-maxage=1800');

    my ($p, $type) = ($self->request->uri =~ m!^/graph/([^/]+)/(\w+).png!);

    # people breaking the varnish cache by adding query parameters
    if (keys %{$self->request->query_parameters}) {
        return $self->redirect($self->request->uri, 301);
    }

    my ($server) = $p && NP::Model->server->find_server($p);
    return 404 unless $server;
    return 404 unless $type and $type =~ m!^(offset|score)$!;

    # we only have one graph type now
    $type = 'offset';

{'fraction_non_alphanumeric': 0.18793342579750347, 'fraction_numerical': 0.0159500693481276, 'mean_word_length': 4.135231316725979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '215203', 'n_tokens_mistral': 530, 'n_tokens_neox': 488, 'n_words': 128}