LP#1568195: fix retrieving big OUS batches user/gmcharlt/lp1568195_retrieve_big_ous_batches
authorGalen Charlton <gmc@esilibrary.com>
Sat, 9 Apr 2016 00:45:17 +0000 (20:45 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Sat, 9 Apr 2016 00:45:17 +0000 (20:45 -0400)
This patch fixes a regression introduced in LP#1501471
where the Library Settings Editor could fail to retrieve
the values of org unit settings if more than 99 were
requested at a time.

To test
-------
[1] Open the XUL library settings editor and ensure that
    no search filters are in effect. Note that values
    are not displayed for any of the OU settings, and that
    the Pg log contains error messages like this:

    "ERROR: cannot pass more than 100 arguments to a function"

[2] Apply the patch.
[3] Repeat step one, and verify that values are now retrieved
    for all of the OU settings that have values set.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm

index 1378a47..497d627 100644 (file)
@@ -16,7 +16,7 @@ use UUID::Tiny;
 use Encode;
 use DateTime;
 use DateTime::Format::ISO8601;
-use List::MoreUtils qw/uniq/;
+use List::MoreUtils qw/uniq natatime/;
 use Digest::MD5 qw(md5_hex);
 
 # ---------------------------------------------------------------------------
@@ -1315,14 +1315,22 @@ sub ou_ancestor_setting_batch_insecure {
     my( $self, $orgid, $names ) = @_;
 
     my %result = map { $_ => undef } @$names;
-    my $query = {from => ['actor.org_unit_ancestor_setting_batch', $orgid, @$names]};
     my $e = OpenILS::Utils::CStoreEditor->new();
-    my $settings = $e->json_query($query);
-    foreach my $setting (@$settings) {
-        $result{$setting->{name}} = {
-            org => $setting->{org_unit},
-            value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})
-        };
+
+    # LP#1568195: retrieve settings 90 at a time; the value 90 comes
+    # from the default maximum number of arguments that PostgreSQL
+    # allows # for variadic functions (100), less one for the OU 
+    # parameter and less nine for a fudge factor.
+    my $iter = natatime 90, @$names;
+    while (my @names_chunk = $iter->()) {
+        my $query = {from => ['actor.org_unit_ancestor_setting_batch', $orgid, @names_chunk]};
+        my $settings = $e->json_query($query);
+        foreach my $setting (@$settings) {
+            $result{$setting->{name}} = {
+                org => $setting->{org_unit},
+                value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})
+            };
+        }
     }
     return %result;
 }