JBAS-1741 Targeter fetches holds in batches
authorBill Erickson <berickxx@gmail.com>
Tue, 30 May 2017 16:57:07 +0000 (12:57 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm

index a721f8a..346fc3d 100644 (file)
@@ -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 {