From ba9debf87f6f4adbcef910703e940f40e9d4b9d7 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 3 Aug 2021 10:55:32 -0400 Subject: [PATCH] Adjust the logic to toss previous copy if there are locals and we are in the hard stall interval Signed-off-by: Mike Rylander --- .../src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm index 64f19706f7..31b8852cb0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm @@ -301,6 +301,7 @@ sub hold { sub inside_hard_stall_interval { my ($self) = @_; if (defined $self->{inside_hard_stall_interval}) { + $self->log_hold('already looked up hard stalling state: '.$self->{inside_hard_stall_interval}); return $self->{inside_hard_stall_interval}; } @@ -308,6 +309,8 @@ sub inside_hard_stall_interval { $self->parent->get_ou_setting( $self->hold->pickup_lib, 'circ.pickup_hold_stalling.hard', $self->editor) || '0 seconds'; + $self->log_hold('hard stalling interval '.$hard_stall_interval); + my $hold_request_time = $dt_parser->parse_datetime(clean_ISO8601($self->hold->request_time)); my $hard_stall_time = $hold_request_time->clone->add( seconds => OpenILS::Utils::DateTime->interval_to_seconds($hard_stall_interval) @@ -319,6 +322,7 @@ sub inside_hard_stall_interval { $self->{inside_hard_stall_interval} = 0 } + $self->log_hold('hard stalling state: '.$self->{inside_hard_stall_interval}); return $self->{inside_hard_stall_interval}; } @@ -769,6 +773,12 @@ sub compile_weighted_proximity_map { $copy_hash->{proximity} = $prox; } + # We also need the proximity for the previous target. + if ($self->{valid_previous_copy}) { + my $prox = $copy_prox_map{$self->{valid_previous_copy}->{id}}; + $self->{valid_previous_copy}->{proximity} = $prox; + } + return $self->{weighted_prox_map} = \%prox_map; } @@ -963,7 +973,7 @@ sub attempt_force_recall_target { sub attempt_to_find_copy { my $self = shift; - return undef unless @{$self->copies}; + $self->log_hold("attempting to find a copy normally"); my $max_loops = $self->parent->get_ou_setting( $self->hold->pickup_lib, @@ -1151,24 +1161,32 @@ sub find_nearest_copy { if (grep { $_->{proximity} <= 0 } @{$self->in_use_copies}) { $have_local_copies = 1; } + $self->log_hold("inside hard stall interval and does ". + ($have_local_copies ? "" : "not "). "have in-use local copies"); } # Pick a copy at random from each tier of the proximity map, # starting at the lowest proximity and working up, until a # copy is found that is suitable for targeting. + my $no_copies = 1; for my $prox (sort {$a <=> $b} keys %prox_map) { my @copies = @{$prox_map{$prox}}; next unless @copies; + $no_copies = 0; $have_local_copies = 1 if ($prox <= 0); - if ($prox > 0 and $have_local_copies and $self->inside_hard_stall_interval) { + $self->log_hold("inside hard stall interval and does ". + ($have_local_copies ? "" : "not "). "have testable local copies") + if ($self->inside_hard_stall_interval && $prox > 0); + + if ($have_local_copies and $self->inside_hard_stall_interval) { # Unset valid_previous_copy if it's not local and we have local copies now $self->{valid_previous_copy} = undef if ( $self->{valid_previous_copy} and $self->{valid_previous_copy}->{proximity} > 0 ); - last; # No point in looking further "out". + last if ($prox > 0); # No point in looking further "out". } my $rand = int(rand(scalar(@copies))); @@ -1184,6 +1202,14 @@ sub find_nearest_copy { } } + if ($no_copies and $have_local_copies and $self->inside_hard_stall_interval) { + # Unset valid_previous_copy if it's not local and we have local copies now + $self->{valid_previous_copy} = undef if ( + $self->{valid_previous_copy} + and $self->{valid_previous_copy}->{proximity} > 0 + ); + } + return undef; } -- 2.11.0