added json_query support to cstoreEditor. using said support to tune the title-hold...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jan 2007 21:48:47 +0000 (21:48 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jan 2007 21:48:47 +0000 (21:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6834 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index fee7daa..c92d124 100644 (file)
@@ -1088,15 +1088,11 @@ sub _check_title_hold_is_possible {
    
    my $e = new_editor();
 
-   # this monster will grab all "holdable" copies for the given record
+=head old
    my $copies = $e->search_asset_copy(
       [
          { deleted => 'f', circulate => 't', holdable => 't' },
-         {  #flesh => 1,
-            #flesh_fields => {
-            #   acp => ['circ_lib']
-            #},
-            join_filter => {
+         {  'join' => {
                acpl  => {
                   field => 'id',
                   fkey => 'location',
@@ -1110,7 +1106,7 @@ sub _check_title_hold_is_possible {
                acn => {
                   field => 'id',
                   fkey => 'call_number',
-                  join_filter => {
+                  'join' => {
                      bre => {
                         field => 'id',
                         fkey => 'record',
@@ -1122,7 +1118,36 @@ sub _check_title_hold_is_possible {
          }
       ],
    );
+=cut
+
+    # this monster will grab the id and circ_lib of all of the "holdable" copies for the given record
+    my $copies = $e->json_query(
+        { 
+            select => { acp => ['id', 'circ_lib'] },
+            from => {
+                acp => {
+                    acn => {
+                        field => 'id',
+                        fkey => 'call_number',
+                        'join' => {
+                            bre => {
+                                field => 'id',
+                                filter => { id => $titleid },
+                                fkey => 'record'
+                            }
+                        }
+                    },
+                    acpl => { field => 'id', filter => { holdable => 't'}, fkey => 'location' },
+                    ccs => { field => 'id', filter => { holdable => 't'}, fkey => 'status' }
+                }
+            }, 
+            where => {
+                '+acp' => { circulate => 't', deleted => 'f', holdable => 't' }
+            }
+        }
+    );
 
+   return $e->event unless defined $copies;
    $logger->info("title possible found ".scalar(@$copies)." potential copies");
    return 0 unless @$copies;
 
@@ -1141,7 +1166,7 @@ sub _check_title_hold_is_possible {
 
    my %buckets;
    my %hash = map { ($_->to_org => $_->prox) } @$home_prox;
-   push( @{$buckets{ $hash{$_->circ_lib} } }, $_ ) for @$copies;
+   push( @{$buckets{ $hash{$_->{circ_lib}} } }, $_->{id} ) for @$copies;
 
    my @keys = sort { $a <=> $b } keys %buckets;
 
@@ -1159,7 +1184,7 @@ sub _check_title_hold_is_possible {
 
       my %buckets2;
       my %hash2 = map { ($_->to_org => $_->prox) } @$req_prox;
-      push( @{$buckets2{ $hash2{$_->circ_lib} } }, $_ ) for @$copies;
+      push( @{$buckets2{ $hash2{$_->{circ_lib}} } }, $_->{id} ) for @$copies;
 
       my $highest_key = $keys[@keys - 1];  # the farthest prox in the exising buckets
       my $new_key = $highest_key - 0.5; # right before the farthest prox
@@ -1179,11 +1204,12 @@ sub _check_title_hold_is_possible {
 
       $logger->info("looking at " . scalar(@{$buckets{$key}}). " copies in proximity bucket $key");
 
-      for my $copy (@cps) {
+      for my $copyid (@cps) {
 
-         next if $seen{$copy->id};
-         $seen{$copy->id} = 1; # there could be dupes given the merged buckets
-         $logger->debug("looking at bucket_key=$key, copy ".$copy->id." : circ_lib = " . $copy->circ_lib);
+         next if $seen{$copyid};
+         $seen{$copyid} = 1; # there could be dupes given the merged buckets
+         my $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
+         $logger->debug("looking at bucket_key=$key, copy $copyid : circ_lib = " . $copy->circ_lib);
 
          unless($title) { # grab the title if we don't already have it
             my $vol = $e->retrieve_asset_call_number(
index 71a9117..fa4a142 100644 (file)
@@ -473,13 +473,13 @@ sub runmethod {
        my $method = $self->app.".direct.$type.$action";
 
        if( $action eq 'search' ) {
-               $method = "$method.atomic";
+               $method .= '.atomic';
 
        } elsif( $action eq 'batch_retrieve' ) {
                $action = 'search';
                @arg = ( { id => $arg } );
                $method =~ s/batch_retrieve/search/o;
-               $method = "$method.atomic";
+               $method .= '.atomic';
 
        } elsif( $action eq 'retrieve_all' ) {
                $action = 'search';
@@ -488,12 +488,12 @@ sub runmethod {
                $tt =~ s/\./::/og;
                my $fmobj = "Fieldmapper::$tt";
                @arg = ( { $fmobj->Identity => { '!=' => undef } } );
-               $method = "$method.atomic";
+               $method .= '.atomic';
        }
 
        $method =~ s/search/id_list/o if $options->{idlist};
 
-   $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
+    $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
 
        # remove any stale events
        $self->clear_event;
@@ -561,7 +561,7 @@ sub runmethod {
                return undef;
        }
 
-       if( $action eq 'search' or $action eq 'batch_retrieve' or $action eq 'retrieve_all') {
+       if( $action eq 'search' ) {
                $self->log(I, "$type.$action : returned ".scalar(@$obj). " result(s)");
                $self->event(_mk_not_found($type, $arg)) unless @$obj;
        }
@@ -640,6 +640,31 @@ for my $object (keys %$map) {
        eval $retrieveallf;
 }
 
+sub json_query {
+    my( $self, $arg, $options ) = @_;
+    $options ||= {};
+       my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
+    my $method = $self->app.'.json_query.atomic';
+    $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
+       $self->clear_event;
+    my $obj;
+    my $err;
+    
+    try {
+        $obj = $self->request($method, @arg);
+    } catch Error with { $err = shift; };
+
+    if( $err ) {
+        $self->event(
+            OpenILS::Event->new( 'DATABASE_QUERY_FAILED',
+            payload => $arg, debug => "$err" ));
+        return undef;
+    }
+
+    $self->log(I, "json_query : returned ".scalar(@$obj). " result(s)");
+    return $obj;
+}
+
 
 
 1;