From 03937e13028611cf556c3138c15885ef69a3841f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 8 Apr 2016 20:45:17 -0400 Subject: [PATCH] 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 --- .../perlmods/lib/OpenILS/Application/AppUtils.pm | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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; } -- 2.11.0