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 176-191
Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets
Link Here
|
176 |
=cut |
178 |
=cut |
177 |
|
179 |
|
178 |
sub CreateQueue { |
180 |
sub CreateQueue { |
179 |
my $dbh = C4::Context->dbh; |
181 |
my $loops = shift || 1; |
|
|
182 |
|
183 |
my $dbh = C4::Context->dbh; |
180 |
|
184 |
|
181 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
185 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
182 |
$dbh->do("DELETE FROM hold_fill_targets"); |
186 |
$dbh->do("DELETE FROM hold_fill_targets"); |
183 |
|
187 |
|
184 |
my $total_bibs = 0; |
|
|
185 |
my $total_requests = 0; |
186 |
my $total_available_items = 0; |
187 |
my $num_items_mapped = 0; |
188 |
|
189 |
my $branches_to_use; |
188 |
my $branches_to_use; |
190 |
my $transport_cost_matrix; |
189 |
my $transport_cost_matrix; |
191 |
my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix"); |
190 |
my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix"); |
Lines 202-220
sub CreateQueue {
Link Here
|
202 |
|
201 |
|
203 |
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests(); |
202 |
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests(); |
204 |
|
203 |
|
|
|
204 |
# Split the list of bibs into groups to run in parallel |
205 |
if ( $loops > 1 ) { |
206 |
my $bibs_per_chunk = ceil( scalar @$bibs_with_pending_requests / $loops ); |
207 |
my @chunks; |
208 |
|
209 |
push( @chunks, [ splice @$bibs_with_pending_requests, 0, $bibs_per_chunk ] ) while @$bibs_with_pending_requests; |
210 |
push( @{$chunks[0]}, @$bibs_with_pending_requests ); # Add any remainders to the first parallel process |
211 |
|
212 |
my $pl = Parallel::Loops->new($loops); |
213 |
$pl->foreach( \@chunks, sub { |
214 |
_ProcessBiblios($_); |
215 |
}); |
216 |
} else { |
217 |
_ProcessBiblios($bibs_with_pending_requests, $branches_to_use, $transport_cost_matrix); |
218 |
} |
219 |
} |
220 |
|
221 |
=head2 _ProcessBiblios |
222 |
|
223 |
=cut |
224 |
|
225 |
sub _ProcessBiblios { |
226 |
my $bibs_with_pending_requests = shift; |
227 |
my $branches_to_use = shift; |
228 |
my $transport_cost_matrix = shift; |
229 |
|
205 |
foreach my $biblionumber (@$bibs_with_pending_requests) { |
230 |
foreach my $biblionumber (@$bibs_with_pending_requests) { |
206 |
$total_bibs++; |
|
|
207 |
my $hold_requests = GetPendingHoldRequestsForBib($biblionumber); |
231 |
my $hold_requests = GetPendingHoldRequestsForBib($biblionumber); |
208 |
my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use); |
232 |
my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use); |
209 |
$total_requests += scalar(@$hold_requests); |
|
|
210 |
$total_available_items += scalar(@$available_items); |
211 |
|
233 |
|
212 |
my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
234 |
my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
213 |
$item_map or next; |
235 |
$item_map or next; |
214 |
my $item_map_size = scalar(keys %$item_map) |
236 |
my $item_map_size = scalar(keys %$item_map) |
215 |
or next; |
237 |
or next; |
216 |
|
238 |
|
217 |
$num_items_mapped += $item_map_size; |
|
|
218 |
CreatePicklistFromItemMap($item_map); |
239 |
CreatePicklistFromItemMap($item_map); |
219 |
AddToHoldTargetMap($item_map); |
240 |
AddToHoldTargetMap($item_map); |
220 |
if (($item_map_size < scalar(@$hold_requests )) and |
241 |
if (($item_map_size < scalar(@$hold_requests )) and |