aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet/Problem.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/FixMyStreet/DB/ResultSet/Problem.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/FixMyStreet/DB/ResultSet/Problem.pm')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 98bd7c68f..8f0d23080 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -20,6 +20,18 @@ sub set_restriction {
$site_key = $key;
}
+sub to_body {
+ my ($rs, $bodies) = @_;
+ return $rs unless $bodies;
+ unless (ref $bodies eq 'ARRAY') {
+ $bodies = [ map { ref $_ ? $_->id : $_ } $bodies ];
+ }
+ $rs = $rs->search(
+ \[ "regexp_split_to_array(bodies_str, ',') && ?", [ {} => $bodies ] ]
+ );
+ return $rs;
+}
+
# Front page statistics
sub recent_fixed {
@@ -320,9 +332,8 @@ sub send_reports {
$cobrand->process_additional_metadata_for_email($row, \%h);
}
- my @bodies = split /,/, $row->bodies_str;
my $bodies = FixMyStreet::App->model("DB::Body")->search(
- { id => \@bodies },
+ { id => $row->bodies_str_ids },
{ order_by => 'name' },
);