From 67103eaea081494f47a881e80e411e949122ee28 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 30 May 2017 12:57:07 -0400 Subject: [PATCH] JBAS-1741 Targeter fetches holds in batches Avoid clobbering the jabber servers with hundreds of thousands of hold ID messages by grouping the hold IDs into messages of 10k IDs each. Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm index a721f8a06a..346fc3db10 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm @@ -121,9 +121,26 @@ sub find_holds_to_target { [{class => 'ahr', field => 'request_time', direction => 'DESC'}] if $self->{newest_first}; - my $holds = $self->editor->json_query($query, {substream => 1}); + # KCLS JBAS-1741 + # Fetch hold IDs in pages so that multiple IDs can be packaged per + # message, saving a lot of osrf message boilerplate bulk, without + # creating individual messages so large/extensive ejabberd is too + # busy to allow other messages through, causing delays / timeouts in + # other services. + my @ids; + $query->{offset} = 0; + $query->{limit} = 10000; + while (1) { + my $holds = $self->editor->json_query($query, {timeout => 600}); + push(@ids, map {$_->{id}} @$holds); + + # all done if number of holds retrieved is less than the limit. + last if @$holds < $query->{limit}; + + $query->{offset} += $query->{limit}; + } - return map {$_->{id}} @$holds; + return @ids; } sub editor { -- 2.11.0