View | Details | Raw Unified | Return to bug 28833
Collapse All | Expand All

(-)a/C4/HoldsQueue.pm (-11 / +39 lines)
Lines 30-37 use Koha::Items; Link Here
30
use Koha::Patrons;
30
use Koha::Patrons;
31
use Koha::Libraries;
31
use Koha::Libraries;
32
32
33
use List::Util qw( shuffle );
34
use List::MoreUtils qw( any );
33
use List::MoreUtils qw( any );
34
use List::Util qw( shuffle );
35
use POSIX qw(ceil);
36
use Parallel::ForkManager;
35
37
36
our (@ISA, @EXPORT_OK);
38
our (@ISA, @EXPORT_OK);
37
BEGIN {
39
BEGIN {
Lines 173-188 Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets Link Here
173
=cut
175
=cut
174
176
175
sub CreateQueue {
177
sub CreateQueue {
176
    my $dbh   = C4::Context->dbh;
178
    my $loops = shift || 1;
179
180
    my $dbh = C4::Context->dbh;
177
181
178
    $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
182
    $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
179
    $dbh->do("DELETE FROM hold_fill_targets");
183
    $dbh->do("DELETE FROM hold_fill_targets");
180
184
181
    my $total_bibs            = 0;
182
    my $total_requests        = 0;
183
    my $total_available_items = 0;
184
    my $num_items_mapped      = 0;
185
186
    my $branches_to_use;
185
    my $branches_to_use;
187
    my $transport_cost_matrix;
186
    my $transport_cost_matrix;
188
    my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix");
187
    my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix");
Lines 199-217 sub CreateQueue { Link Here
199
198
200
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
199
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
201
200
201
    # Split the list of bibs into groups to run in parallel
202
    if ( $loops > 1 ) {
203
        my $bibs_per_chunk = ceil( scalar @$bibs_with_pending_requests / $loops );
204
        $bibs_per_chunk = @$bibs_with_pending_requests if @$bibs_with_pending_requests <= $bibs_per_chunk;
205
        my @chunks;
206
207
        push( @chunks, [ splice @$bibs_with_pending_requests, 0, $bibs_per_chunk ] ) while @$bibs_with_pending_requests;
208
        push( @{$chunks[0]}, @$bibs_with_pending_requests ); # Add any remainders to the first parallel process
209
210
        my $pm = Parallel::ForkManager->new($loops);
211
212
        DATA_LOOP:
213
        foreach my $chunk (@chunks) {
214
            my $pid = $pm->start and next DATA_LOOP;
215
            _ProcessBiblios( $chunk, $branches_to_use, $transport_cost_matrix );
216
            $pm->finish;
217
        }
218
219
        $pm->wait_all_children;
220
    } else {
221
        _ProcessBiblios( $bibs_with_pending_requests, $branches_to_use, $transport_cost_matrix );
222
    }
223
}
224
225
=head2 _ProcessBiblios
226
227
=cut
228
229
sub _ProcessBiblios {
230
    my $bibs_with_pending_requests = shift;
231
    my $branches_to_use = shift;
232
    my $transport_cost_matrix = shift;
233
202
    foreach my $biblionumber (@$bibs_with_pending_requests) {
234
    foreach my $biblionumber (@$bibs_with_pending_requests) {
203
        $total_bibs++;
204
        my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
235
        my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
205
        my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
236
        my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
206
        $total_requests        += scalar(@$hold_requests);
207
        $total_available_items += scalar(@$available_items);
208
237
209
        my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
238
        my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
210
        $item_map  or next;
239
        $item_map  or next;
211
        my $item_map_size = scalar(keys %$item_map)
240
        my $item_map_size = scalar(keys %$item_map)
212
          or next;
241
          or next;
213
242
214
        $num_items_mapped += $item_map_size;
215
        CreatePicklistFromItemMap($item_map);
243
        CreatePicklistFromItemMap($item_map);
216
        AddToHoldTargetMap($item_map);
244
        AddToHoldTargetMap($item_map);
217
        if (($item_map_size < scalar(@$hold_requests  )) and
245
        if (($item_map_size < scalar(@$hold_requests  )) and
(-)a/debian/templates/koha-conf-site.xml.in (+4 lines)
Lines 449-453 __END_SRU_PUBLICSERVER__ Link Here
449
   <vhost>__MESSAGE_BROKER_VHOST__</vhost>
449
   <vhost>__MESSAGE_BROKER_VHOST__</vhost>
450
 </message_broker>
450
 </message_broker>
451
451
452
 <holds_queue_builder>
453
     <parallel_loops_count>1</parallel_loops_count>
454
 </holds_queue_builder>
455
452
</config>
456
</config>
453
</yazgfs>
457
</yazgfs>
(-)a/etc/koha-conf.xml (+4 lines)
Lines 266-270 Link Here
266
   <vhost></vhost>
266
   <vhost></vhost>
267
 </message_broker>
267
 </message_broker>
268
268
269
 <holds_queue_builder>
270
     <parallel_loops_count>1</parallel_loops_count>
271
 </holds_queue_builder>
272
269
</config>
273
</config>
270
</yazgfs>
274
</yazgfs>
(-)a/misc/cronjobs/holds/build_holds_queue.pl (-2 / +3 lines)
Lines 18-25 BEGIN { Link Here
18
use Koha::Script -cron;
18
use Koha::Script -cron;
19
use C4::HoldsQueue qw(CreateQueue);
19
use C4::HoldsQueue qw(CreateQueue);
20
use C4::Log qw( cronlogaction );
20
use C4::Log qw( cronlogaction );
21
use C4::Context;
21
22
22
cronlogaction();
23
cronlogaction();
23
24
24
CreateQueue();
25
my $loops = C4::Context->config('holds_queue_builder')->{parallel_loops_count};
26
CreateQueue($loops);
25
27
26
- 

Return to bug 28833