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

(-)a/C4/HoldsQueue.pm (-25 / +39 lines)
Lines 33-41 use Koha::Items; Link Here
33
use Koha::Patrons;
33
use Koha::Patrons;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
35
36
use List::Util qw(shuffle);
37
use List::MoreUtils qw(any);
38
use Data::Dumper;
36
use Data::Dumper;
37
use List::MoreUtils qw(any);
38
use List::Util qw(shuffle);
39
use POSIX qw(ceil);
40
use Parallel::Loops;
39
41
40
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
42
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
41
BEGIN {
43
BEGIN {
Lines 202-230 sub CreateQueue { Link Here
202
204
203
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
205
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
204
206
205
    foreach my $biblionumber (@$bibs_with_pending_requests) {
207
    # Split the list of bibs into groups to run in parallel
206
        $total_bibs++;
208
    my $chunks_count = 10;
207
        my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
209
    my $bibs_per_chunk = ceil( scalar @$bibs_with_pending_requests / $chunks_count );
208
        my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
210
    my @chunks;
209
        $total_requests        += scalar(@$hold_requests);
211
210
        $total_available_items += scalar(@$available_items);
212
    push( @chunks, [ splice @$bibs_with_pending_requests, 0, $bibs_per_chunk ] ) while @$bibs_with_pending_requests;
211
213
    push( @{$chunks[0]}, @$bibs_with_pending_requests ); # Add any remainders to the first parallel process
212
        my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
214
213
        $item_map  or next;
215
    my $pl = Parallel::Loops->new($chunks_count);
214
        my $item_map_size = scalar(keys %$item_map)
216
    $pl->foreach( \@chunks, sub {
215
          or next;
217
        $bibs_with_pending_requests = $_;
216
218
217
        $num_items_mapped += $item_map_size;
219
        foreach my $biblionumber (@$bibs_with_pending_requests) {
218
        CreatePicklistFromItemMap($item_map);
220
            $total_bibs++;
219
        AddToHoldTargetMap($item_map);
221
            my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
220
        if (($item_map_size < scalar(@$hold_requests  )) and
222
            my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
221
            ($item_map_size < scalar(@$available_items))) {
223
            $total_requests        += scalar(@$hold_requests);
222
            # DOUBLE CHECK, but this is probably OK - unfilled item-level requests
224
            $total_available_items += scalar(@$available_items);
223
            # FIXME
225
224
            #warn "unfilled requests for $biblionumber";
226
            my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
225
            #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map);
227
            $item_map  or next;
228
            my $item_map_size = scalar(keys %$item_map)
229
              or next;
230
231
            $num_items_mapped += $item_map_size;
232
            CreatePicklistFromItemMap($item_map);
233
            AddToHoldTargetMap($item_map);
234
            if (($item_map_size < scalar(@$hold_requests  )) and
235
                ($item_map_size < scalar(@$available_items))) {
236
                # DOUBLE CHECK, but this is probably OK - unfilled item-level requests
237
                # FIXME
238
                #warn "unfilled requests for $biblionumber";
239
                #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map);
240
            }
226
        }
241
        }
227
    }
242
    });
228
}
243
}
229
244
230
=head2 GetBibsWithPendingHoldRequests
245
=head2 GetBibsWithPendingHoldRequests
231
- 

Return to bug 28833