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