aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/GetServiceRequestUpdates.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-08-17 17:12:26 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-08-19 15:47:20 +0100
commit5c79337ad423cd7fc3cada9b7830d90726387987 (patch)
tree61615747eae7483722bea4c94309ef4d1cddac4c /perllib/Open311/GetServiceRequestUpdates.pm
parentf5d6ec933c9fd4d57f9b56fec27f7c746a0706b9 (diff)
Simplify/consolidate body restriction db code.
Make dashboard work properly in two-tier councils, showing reports sent to both. Create an index on the array of the bodies_str column to speed up performance, and use that throughout the code replacing all LIKE scans. This also enables a simplifying tidy of the restriction code.
Diffstat (limited to 'perllib/Open311/GetServiceRequestUpdates.pm')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm12
1 files changed, 5 insertions, 7 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index f7b758137..1e5f4dc6b 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -48,12 +48,12 @@ sub fetch {
$self->suppress_alerts( $body->suppress_alerts );
$self->system_user( $body->comment_user );
- $self->update_comments( $o, { areas => $body->areas }, );
+ $self->update_comments( $o, $body );
}
}
sub update_comments {
- my ( $self, $open311, $body_details ) = @_;
+ my ( $self, $open311, $body ) = @_;
my @args = ();
@@ -63,7 +63,7 @@ sub update_comments {
push @args, $self->start_date;
push @args, $self->end_date;
# default to asking for last 2 hours worth if not Bromley
- } elsif ( ! $body_details->{areas}->{$AREA_ID_BROMLEY} ) {
+ } elsif ( ! $body->areas->{$AREA_ID_BROMLEY} ) {
my $end_dt = DateTime->now();
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -2 );
@@ -75,7 +75,7 @@ sub update_comments {
my $requests = $open311->get_service_request_updates( @args );
unless ( $open311->success ) {
- warn "Failed to fetch ServiceRequest Updates for " . join(",", keys %{$body_details->{areas}}) . ":\n" . $open311->error
+ warn "Failed to fetch ServiceRequest Updates for " . $body->name . ":\n" . $open311->error
if $self->verbose;
return 0;
}
@@ -90,10 +90,8 @@ sub update_comments {
my $problem;
my $criteria = {
external_id => $request_id,
- # XXX This assumes that areas will actually only be one area.
- bodies_str => { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' },
};
- $problem = FixMyStreet::App->model('DB::Problem')->search( $criteria );
+ $problem = FixMyStreet::App->model('DB::Problem')->to_body($body)->search( $criteria );
if (my $p = $problem->first) {
my $c = $p->comments->search( { external_id => $request->{update_id} } );