my($self, $conn, $target_id, $args) = @_;
$args ||= {};
+ # KCLS JBAS-2024
+ return rec_hold_count_via_rhrr($target_id, $args)
+ unless $self->api_name =~ /mmr/;
+
my $mmr_join = {
mmrsm => {
field => 'source',
'+ahr' => {
cancel_time => undef,
fulfillment_time => undef,
-# KCLS JBAS-826 -- make the record hold counts query faster by only
-# counting bib-level holds (which represent >99% of KCLS' holds).
- hold_type => 'T',
- target => $target_id
-# '-or' => [
-# {
-# '-and' => {
-# hold_type => [qw/C F R/],
-# target => {
-# in => {
-# select => {acp => ['id']},
-# from => { acp => $cn_join }
-# }
-# }
-# }
-# },
-# {
-# '-and' => {
-# hold_type => 'V',
-# target => {
-# in => {
-# select => {acn => ['id']},
-# from => {acn => $bre_join}
-# }
-# }
-# }
-# },
-# {
-# '-and' => {
-# hold_type => 'P',
-# target => {
-# in => {
-# select => {bmp => ['id']},
-# from => {bmp => $bre_join}
-# }
-# }
-# }
-# },
-# {
-# '-and' => {
-# hold_type => 'T',
-# target => $target_id
-# }
-# }
-# ]
+ '-or' => [
+ {
+ '-and' => {
+ hold_type => [qw/C F R/],
+ target => {
+ in => {
+ select => {acp => ['id']},
+ from => { acp => $cn_join }
+ }
+ }
+ }
+ },
+ {
+ '-and' => {
+ hold_type => 'V',
+ target => {
+ in => {
+ select => {acn => ['id']},
+ from => {acn => $bre_join}
+ }
+ }
+ }
+ },
+ {
+ '-and' => {
+ hold_type => 'P',
+ target => {
+ in => {
+ select => {bmp => ['id']},
+ from => {bmp => $bre_join}
+ }
+ }
+ }
+ },
+ {
+ '-and' => {
+ hold_type => 'T',
+ target => $target_id
+ }
+ }
+ ]
}
}
};
return new_editor()->json_query($query)->[0]->{count};
}
+# KCLS JBAS-2024
+sub rec_hold_count_via_rhrr {
+ my ($target_id, $args) = @_;
+ $args ||= {};
+
+ # TODO: add metarecord holds count support by counting holds
+ # in rhrr that link to the master record.
+ # TODO: post to LP
+
+ my $query = {
+ select => {rhrr => [
+ {column => 'id', transform => 'count', alias => 'count'}
+ ]},
+ from => {rhrr => 'ahr'},
+ where => {
+ '+rhrr' => {bib_record => $target_id},
+ '+ahr' => {
+ cancel_time => undef,
+ fulfillment_time => undef
+ }
+ }
+ };
+
+ if (my $pld = $args->{pickup_lib_descendant}) {
+
+ my $top_ou =
+ new_editor()->search_actor_org_unit(
+ {parent_ou => undef})->[0];
+
+ $query->{where}->{'+ahr'}->{pickup_lib} = {
+ in => {
+ select => {aou => [{
+ column => 'id',
+ transform => 'actor.org_unit_descendants',
+ result_field => 'id'
+ }]},
+ from => 'aou',
+ where => {id => $pld}
+ }
+ } if ($pld != $top_ou->id);
+ }
+
+ return new_editor()->json_query($query)->[0]->{count};
+}
+
+
# A helper function to calculate a hold's expiration time at a given
# org_unit. Takes the org_unit as an argument and returns either the
# hold expire time as an ISO8601 string or undef if there is no hold