|
Lines 30-37
use Koha::Items;
Link Here
|
| 30 |
use Koha::Libraries; |
30 |
use Koha::Libraries; |
| 31 |
use Koha::Patrons; |
31 |
use Koha::Patrons; |
| 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 166-181
Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets
Link Here
|
| 166 |
=cut |
168 |
=cut |
| 167 |
|
169 |
|
| 168 |
sub CreateQueue { |
170 |
sub CreateQueue { |
|
|
171 |
my $loops = shift || 1; |
| 172 |
|
| 169 |
my $dbh = C4::Context->dbh; |
173 |
my $dbh = C4::Context->dbh; |
| 170 |
|
174 |
|
| 171 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
175 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
| 172 |
$dbh->do("DELETE FROM hold_fill_targets"); |
176 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 173 |
|
177 |
|
| 174 |
my $total_bibs = 0; |
|
|
| 175 |
my $total_requests = 0; |
| 176 |
my $total_available_items = 0; |
| 177 |
my $num_items_mapped = 0; |
| 178 |
|
| 179 |
my $branches_to_use; |
178 |
my $branches_to_use; |
| 180 |
my $transport_cost_matrix; |
179 |
my $transport_cost_matrix; |
| 181 |
my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix"); |
180 |
my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix"); |
|
Lines 191-199
sub CreateQueue {
Link Here
|
| 191 |
|
190 |
|
| 192 |
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests(); |
191 |
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests(); |
| 193 |
|
192 |
|
| 194 |
foreach my $biblionumber (@$bibs_with_pending_requests) { |
193 |
# Split the list of bibs into chunks to run in parallel |
|
|
194 |
my @chunks; |
| 195 |
if ( $loops > 1 ) { |
| 196 |
my $i = 0; |
| 197 |
while (@$bibs_with_pending_requests) { |
| 198 |
push( @{ $chunks[$i] }, pop(@$bibs_with_pending_requests) ); |
| 199 |
|
| 200 |
$i++; |
| 201 |
$i = 0 if $i >= $loops; |
| 202 |
} |
| 203 |
|
| 204 |
my $pm = Parallel::ForkManager->new($loops); |
| 205 |
|
| 206 |
DATA_LOOP: |
| 207 |
foreach my $chunk (@chunks) { |
| 208 |
my $pid = $pm->start and next DATA_LOOP; |
| 209 |
_ProcessBiblios( $chunk, $branches_to_use, $transport_cost_matrix ); |
| 210 |
$pm->finish; |
| 211 |
} |
| 195 |
|
212 |
|
| 196 |
$total_bibs++; |
213 |
$pm->wait_all_children; |
|
|
214 |
} else { |
| 215 |
_ProcessBiblios( $bibs_with_pending_requests, $branches_to_use, $transport_cost_matrix ); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
=head2 _ProcessBiblios |
| 220 |
|
| 221 |
=cut |
| 222 |
|
| 223 |
sub _ProcessBiblios { |
| 224 |
my $bibs_with_pending_requests = shift; |
| 225 |
my $branches_to_use = shift; |
| 226 |
my $transport_cost_matrix = shift; |
| 227 |
|
| 228 |
foreach my $biblionumber (@$bibs_with_pending_requests) { |
| 197 |
|
229 |
|
| 198 |
my $result = update_queue_for_biblio( |
230 |
my $result = update_queue_for_biblio( |
| 199 |
{ biblio_id => $biblionumber, |
231 |
{ biblio_id => $biblionumber, |
|
Lines 201-210
sub CreateQueue {
Link Here
|
| 201 |
transport_cost_matrix => $transport_cost_matrix, |
233 |
transport_cost_matrix => $transport_cost_matrix, |
| 202 |
} |
234 |
} |
| 203 |
); |
235 |
); |
| 204 |
|
|
|
| 205 |
$total_requests += $result->{requests}; |
| 206 |
$total_available_items += $result->{available_items}; |
| 207 |
$num_items_mapped += $result->{mapped_items}; |
| 208 |
} |
236 |
} |
| 209 |
} |
237 |
} |
| 210 |
|
238 |
|
|
Lines 220-231
that have one or more unfilled hold requests.
Link Here
|
| 220 |
sub GetBibsWithPendingHoldRequests { |
248 |
sub GetBibsWithPendingHoldRequests { |
| 221 |
my $dbh = C4::Context->dbh; |
249 |
my $dbh = C4::Context->dbh; |
| 222 |
|
250 |
|
| 223 |
my $bib_query = "SELECT DISTINCT biblionumber |
251 |
my $bib_query = "SELECT biblionumber, |
| 224 |
FROM reserves |
252 |
COUNT(biblionumber) AS holds_count |
| 225 |
WHERE found IS NULL |
253 |
FROM reserves |
| 226 |
AND priority > 0 |
254 |
WHERE found IS NULL |
| 227 |
AND reservedate <= CURRENT_DATE() |
255 |
AND priority > 0 |
| 228 |
AND suspend = 0 |
256 |
AND reservedate <= CURRENT_DATE() |
|
|
257 |
AND suspend = 0 |
| 258 |
GROUP BY biblionumber |
| 259 |
ORDER BY biblionumber DESC |
| 229 |
"; |
260 |
"; |
| 230 |
my $sth = $dbh->prepare($bib_query); |
261 |
my $sth = $dbh->prepare($bib_query); |
| 231 |
|
262 |
|