LP#1743639: Test location as proxy for location group
authorMike Rylander <mrylander@gmail.com>
Tue, 16 Jan 2018 21:26:31 +0000 (16:26 -0500)
committerKathy Lussier <klussier@masslnc.org>
Wed, 17 Jan 2018 18:12:48 +0000 (13:12 -0500)
Location groups are a table remove from copies, and can cause very large
updates to the copy vis cache.  So, we will expand location groups to
locations, in situ, to avoid this problem and the need to supply a trigger
to update th copy vis cache for groups.  This will allow us to reclaim
the location group bit in the visibility cache namespace if necessary, at
a later date.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Open-ILS/src/sql/Pg/300.schema.staged_search.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.copy_location_group_visible.sql

index 9a02d33..1a3d40a 100644 (file)
@@ -1511,15 +1511,17 @@ sub flatten {
             } elsif ($filter->name eq 'locations') {
                 if (@{$filter->args} > 0) {
                     my $negate = $filter->negate ? 'TRUE' : 'FALSE';
+                    my $filter_args = join(",", map(int, @{$filter->args}));
                     push @{$vis_filter{'c_attr'}},
-                        "search.calculate_visibility_attribute_test('location','{".join(',', @{$filter->args})."}',$negate)";
+                        "search.calculate_visibility_attribute_test('location',$filter_args,$negate)";
                 }
 
             } elsif ($filter->name eq 'location_groups') {
                 if (@{$filter->args} > 0) {
                     my $negate = $filter->negate ? 'TRUE' : 'FALSE';
+                    my $filter_args = join(",", map(int, @{$filter->args}));
                     push @{$vis_filter{'c_attr'}},
-                        "search.calculate_visibility_attribute_test('location_group','{".join(',', @{$filter->args})."}',$negate)";
+                        "search.calculate_visibility_attribute_test('location',(SELECT ARRAY_AGG(location) FROM asset.copy_location_group_map WHERE lgroup IN ($filter_args)),$negate)";
                 }
 
             } elsif ($filter->name eq 'statuses') {
index 5735263..5157aaf 100644 (file)
@@ -761,7 +761,7 @@ CREATE OR REPLACE FUNCTION asset.location_group_default () RETURNS TEXT AS $f$
       FROM  asset.copy_location_group
       WHERE NOT opac_visible;
 */
-$f$ LANGUAGE SQL STABLE;
+$f$ LANGUAGE SQL IMMUTABLE;
 
 CREATE OR REPLACE FUNCTION asset.location_default () RETURNS TEXT AS $f$
     SELECT  '!(' || ARRAY_TO_STRING(ARRAY_AGG(search.calculate_visibility_attribute(id, 'location')),'|') || ')'
index 7b457c6..ca49b54 100644 (file)
@@ -7,7 +7,7 @@ CREATE OR REPLACE FUNCTION asset.location_group_default () RETURNS TEXT AS $f$
       FROM  asset.copy_location_group
       WHERE NOT opac_visible;
 */
-$f$ LANGUAGE SQL STABLE;
+$f$ LANGUAGE SQL IMMUTABLE;
 
 COMMIT;