From: Galen Charlton Date: Sat, 9 Apr 2016 00:45:17 +0000 (-0400) Subject: LP#1568195: fix retrieving big OUS batches X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fgmcharlt%2Flp1568195_retrieve_big_ous_batches;p=working%2FEvergreen.git LP#1568195: fix retrieving big OUS batches 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 --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 1378a471ba..497d627e95 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -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; }