From: berick Date: Thu, 7 Apr 2011 15:14:29 +0000 (-0400) Subject: speed up and clean up the user holds out/available count summary call X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7a715144023cf2818e6b0ba153613cbddbd5061c;p=evergreen%2Fequinox.git speed up and clean up the user holds out/available count summary call --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 9b9bd139f9..864ef6e68a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -1815,39 +1815,31 @@ __PACKAGE__->register_method( ); sub hold_request_count { - my( $self, $client, $login_session, $userid ) = @_; - - my( $user_obj, $target, $evt ) = $apputils->checkses_requestor( - $login_session, $userid, 'VIEW_HOLD' ); - return $evt if $evt; - - - my $holds = $apputils->simple_scalar_request( - "open-ils.cstore", - "open-ils.cstore.direct.action.hold_request.search.atomic", - { - usr => $userid, - fulfillment_time => {"=" => undef }, - cancel_time => undef, - } - ); + my( $self, $client, $authtoken, $user_id ) = @_; + my $e = new_editor(authtoken => $authtoken); + return $e->event unless $e->checkauth; - my @ready; - for my $h (@$holds) { - next unless $h->capture_time and $h->current_copy; + $user_id = $e->requestor->id unless defined $user_id; - my $copy = $apputils->simple_scalar_request( - "open-ils.cstore", - "open-ils.cstore.direct.asset.copy.retrieve", - $h->current_copy - ); + if($e->requestor->id ne $user_id) { + my $user = $e->retrieve_actor_user($user_id); + return $e->event unless $e->allowed('VIEW_HOLD', $user->home_ou); + } - if ($copy and $copy->status == 8) { - push @ready, $h; - } - } + my $holds = $e->json_query({ + select => {ahr => ['shelf_time']}, + from => 'ahr', + where => { + usr => $user_id, + fulfillment_time => {"=" => undef }, + cancel_time => undef, + } + }); - return { total => scalar(@$holds), ready => scalar(@ready) }; + return { + total => scalar(@$holds), + ready => scalar(grep { $_->{shelf_time} } @$holds) + }; } __PACKAGE__->register_method(