aboutsummaryrefslogtreecommitdiffstats
path: root/db/schema_0035-bodies_str-tidying.sql
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 /db/schema_0035-bodies_str-tidying.sql
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 'db/schema_0035-bodies_str-tidying.sql')
-rw-r--r--db/schema_0035-bodies_str-tidying.sql21
1 files changed, 21 insertions, 0 deletions
diff --git a/db/schema_0035-bodies_str-tidying.sql b/db/schema_0035-bodies_str-tidying.sql
index c4c7badaf..f5e1dbbdd 100644
--- a/db/schema_0035-bodies_str-tidying.sql
+++ b/db/schema_0035-bodies_str-tidying.sql
@@ -7,4 +7,25 @@ update problem
bodies_str = split_part(bodies_str, '|', 1)
where bodies_str like '%|%';
+create index problem_bodies_str_array_idx on problem USING gin(regexp_split_to_array(bodies_str, ','));
+
+UPDATE alert_type set item_where =
+ 'problem.non_public = ''f'' and problem.state in
+ (''confirmed'', ''investigating'', ''planned'', ''in progress'',
+ ''fixed'', ''fixed - council'', ''fixed - user'', ''closed'',
+ ''action scheduled'', ''not responsible'', ''duplicate'', ''unable to fix'',
+ ''internal referral'' ) AND
+ regexp_split_to_array(bodies_str, '','') && ARRAY[?]'
+ WHERE ref = 'council_problems';
+
+UPDATE alert_type set item_where =
+ 'problem.non_public = ''f'' and problem.state in
+ (''confirmed'', ''investigating'', ''planned'', ''in progress'',
+ ''fixed'', ''fixed - council'', ''fixed - user'', ''closed'',
+ ''action scheduled'', ''not responsible'', ''duplicate'', ''unable to fix'',
+ ''internal referral'' ) AND
+ (regexp_split_to_array(bodies_str, '','') && ARRAY[?] or bodies_str is null) and
+ areas like ''%,''||?||'',%'''
+ WHERE ref = 'ward_problems';
+
commit;