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

(-)a/C4/HoldsQueue.pm (-25 / +40 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
        warn "COUNT: " . scalar @$bibs_with_pending_requests;
217
        $num_items_mapped += $item_map_size;
219
218
        CreatePicklistFromItemMap($item_map);
220
        foreach my $biblionumber (@$bibs_with_pending_requests) {
219
        AddToHoldTargetMap($item_map);
221
            $total_bibs++;
220
        if (($item_map_size < scalar(@$hold_requests  )) and
222
            my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
221
            ($item_map_size < scalar(@$available_items))) {
223
            my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
222
            # DOUBLE CHECK, but this is probably OK - unfilled item-level requests
224
            $total_requests        += scalar(@$hold_requests);
223
            # FIXME
225
            $total_available_items += scalar(@$available_items);
224
            #warn "unfilled requests for $biblionumber";
226
225
            #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map);
227
            my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
228
            $item_map  or next;
229
            my $item_map_size = scalar(keys %$item_map)
230
              or next;
231
232
            $num_items_mapped += $item_map_size;
233
            CreatePicklistFromItemMap($item_map);
234
            AddToHoldTargetMap($item_map);
235
            if (($item_map_size < scalar(@$hold_requests  )) and
236
                ($item_map_size < scalar(@$available_items))) {
237
                # DOUBLE CHECK, but this is probably OK - unfilled item-level requests
238
                # FIXME
239
                #warn "unfilled requests for $biblionumber";
240
                #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map);
241
            }
226
        }
242
        }
227
    }
243
    });
228
}
244
}
229
245
230
=head2 GetBibsWithPendingHoldRequests
246
=head2 GetBibsWithPendingHoldRequests
231
- 

Return to bug 28833