Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heatmap speed improvements #4755

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions perllib/FixMyStreet/App/Controller/Dashboard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ sub heatmap : Local : Args(0) {
my $parameters = $c->forward( '/reports/load_problems_parameters');

my $where = $parameters->{where};
# Filter includes order_by, rows, and a prefetch entry
my $filter = $parameters->{filter};
# We don't need the rows, as we always want all reports
delete $filter->{rows};

$c->forward('heatmap_filters', [ $where ]);
Expand All @@ -423,6 +425,9 @@ sub heatmap : Local : Args(0) {

if ($c->get_param('ajax')) {
my @pins;
# We don't need any of the prefetched stuff now
delete $filter->{prefetch};
my $problems = $c->cobrand->problems->to_body($body)->search($where, $filter);
while ( my $problem = $problems->next ) {
push @pins, $problem->pin_data('reports');
}
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sub geocode_postcode {
# Bromley pins always yellow
sub pin_colour {
my ( $self, $p, $context ) = @_;
return 'grey' if !$self->owns_problem( $p );
return 'grey' if ($context ne 'reports' && !$self->owns_problem($p));
return 'yellow';
}

Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/CheshireEast.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ sub send_questionnaires { 0 }

sub pin_colour {
my ( $self, $p, $context ) = @_;
return 'grey' if $p->state eq 'not responsible' || !$self->owns_problem( $p );
return 'grey' if $p->state eq 'not responsible' || ($context ne 'reports' && !$self->owns_problem($p));
return 'green' if $p->is_fixed || $p->is_closed;
return 'yellow' if $p->is_in_progress;
return 'red';
Expand Down
3 changes: 1 addition & 2 deletions perllib/FixMyStreet/Cobrand/Lincolnshire.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ Lincolnshire uses the following pin colours:

sub pin_colour {
my ( $self, $p, $context ) = @_;
my $ext_status = $p->get_extra_metadata('external_status_code');

return 'grey'
if $p->state eq 'not responsible' || !$self->owns_problem($p);
if $p->state eq 'not responsible' || ($context ne 'reports' && !$self->owns_problem($p));
return 'orange'
if $p->state eq 'investigating' || $p->state eq 'for triage';
return 'yellow'
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/Oxfordshire.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sub reports_ordering {

sub pin_colour {
my ( $self, $p, $context ) = @_;
return 'grey' unless $self->owns_problem( $p );
return 'grey' if $context ne 'reports' && !$self->owns_problem($p);
return 'grey' if $p->is_closed;
return 'green' if $p->is_fixed;
return 'yellow' if $p->state eq 'confirmed';
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/UKCouncils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ sub owns_problem {
# then show pins for the other council as grey
sub pin_colour {
my ( $self, $p, $context ) = @_;
return 'grey' if !$self->owns_problem( $p );
return 'grey' if $context ne 'reports' && !$self->owns_problem($p);
return $self->next::method($p, $context);
}

Expand Down
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/DB/ResultSet/State.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ sub _hardcoded_states {
# we cache these in the package on first use, and clear on update.

sub clear {
my $rs = shift;
Memcached::set('states', '');
my $cache = $rs->result_source->schema->cache;
delete $cache->{states};
}

sub states {
my $rs = shift;

my $cache = $rs->result_source->schema->cache;
return $cache->{states} if $cache->{states};

my $states = Memcached::get('states');
# If tests are run in parallel, the cached state in Memcached could be
# corrupted by multiple tests changing it at the same time
# uncoverable branch true
if ($states && !FixMyStreet->test_mode) {
# Need to reattach schema
$states->[0]->result_source->schema( $rs->result_source->schema ) if $states->[0];
$cache->{states} = $states;
return $states;
}

Expand All @@ -45,6 +52,7 @@ sub states {
my @states = ($rs->_hardcoded_states, $rs->search(undef, { order_by => 'label' })->all);
$_->translated->{name} = $trans{$_->id} || {} foreach @states;
$states = \@states;
$cache->{states} = $states;
Memcached::set('states', $states);
return $states;
}
Expand Down
Loading