move to unapi.bre for bib/copy-count/slim-holdings retrieval on record results page
authorberick <berick@esilibrary.com>
Fri, 1 Apr 2011 21:45:12 +0000 (17:45 -0400)
committerberick <berick@esilibrary.com>
Fri, 1 Apr 2011 21:45:12 +0000 (17:45 -0400)
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/web/templates/default/opac/parts/misc_util.tt2
Open-ILS/web/templates/default/opac/parts/result/table.tt2

index 272a3fc..fe61149 100644 (file)
@@ -139,13 +139,14 @@ sub load_rresults {
 
     return Apache2::Const::OK if @$rec_ids == 0;
 
-    my ($facets, @data) = $self->get_records_and_facets($rec_ids, $results->{facet_key});
+    my ($facets, @data) = $self->get_records_and_facets(
+        $rec_ids, $results->{facet_key}, {flesh => '{holdings_xml}'});
 
     # shove recs into context in search results order
     for my $rec_id (@$rec_ids) {
         push(
             @{$ctx->{records}},
-            grep { $_->{bre}->id == $rec_id } @data
+            grep { $_->{id} == $rec_id } @data
         );
     }
 
index 18fc5ce..361261e 100644 (file)
@@ -145,12 +145,29 @@ sub generic_redirect {
 }
 
 sub get_records_and_facets {
-    my ($self, $rec_ids, $facet_key) = @_;
-
-    my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
-    my $bre_req = $cstore->request(
-        'open-ils.cstore.direct.biblio.record_entry.search', {id => $rec_ids}
-    );
+    my ($self, $rec_ids, $facet_key, $unapi_args) = @_;
+
+    $unapi_args ||= {};
+    $unapi_args->{loc} ||= $self->ctx->{aou_tree}->()->shortname;
+    $unapi_args->{depth} ||= $self->ctx->{aou_tree}->()->ou_type->depth;
+    $unapi_args->{flesh_depth} ||= 5;
+
+    # XXX Fire in fixed-size batches to prevent larger display limits abusing cstore
+    my @reqs;
+    for my $id (@$rec_ids) {
+        my $ses = OpenSRF::AppSession->create('open-ils.cstore');
+        my $r = $ses->request(
+            'open-ils.cstore.json_query',
+             {from => [
+                'unapi.bre', $id, 'marcxml','record', 
+                $unapi_args->{flesh}, 
+                $unapi_args->{loc}, 
+                $unapi_args->{depth}, 
+                $unapi_args->{flesh_depth}, 
+            ]}
+        );
+        push(@reqs, {req => $r, ses => $ses});
+    }
 
     my $search = OpenSRF::AppSession->create('open-ils.search');
     my $facet_req = $search->request(
@@ -158,28 +175,17 @@ sub get_records_and_facets {
     ) if $facet_key;
 
     my @data;
-    while (my $resp = $bre_req->recv) {
-        my $bre = $resp->content;
-
-        # XXX farm out to multiple cstore sessions before loop,
-        # then collect after
-        my $copy_counts = $self->editor->json_query(
-            {from => ['asset.record_copy_count', 1, $bre->id, 0]}
-        )->[0];
-
-        push @data, {
-            bre => $bre,
-            marc_xml => XML::LibXML->new->parse_string($bre->marc),
-            copy_counts => $copy_counts
-        };
+    for my $req (@reqs) {
+        my $data = $req->{req}->gather(1);
+        $req->{ses}->kill_me;
+        my $xml = XML::LibXML->new->parse_string($data->{'unapi.bre'})->documentElement;
+        my $rec_id =  $xml->find('*[@tag="901"]/*[@code="c"]')->[0]->textContent;
+        push(@data, {id => $rec_id, marc_xml => $xml});
     }
 
-    $cstore->kill_me;
-
     my $facets;
     if ($facet_key) {
         $facets = $facet_req->gather(1);
-
         $facets->{$_} = {
             cmf => $self->ctx->{find_cmf}->($_),
             data => $facets->{$_}
@@ -191,6 +197,7 @@ sub get_records_and_facets {
     return ($facets, @data);
 }
 
+# TODO: blend this code w/ ^-- get_records_and_facets
 sub fetch_marc_xml_by_id {
     my ($self, $id_list) = @_;
     $id_list = [$id_list] unless ref($id_list);
index 482481d..284b0a3 100644 (file)
         # clean up the ISBN
         args.isbn_clean = args.isbn.replace('\ .*', '');
 
+        args.holdsing = [];
+        FOR holding IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
+            args.holdings.push({
+                # TODO
+            });
+        END;
+
+        # Extract the copy count summary
+        count_type = (ctx.is_staff) ? 'staff' : 'public';
+        xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
+        FOR node IN xml.findnodes(xpath);
+            args.copy_counts = {};
+            FOR attr IN ['count', 'available', 'unshadow', 'transcendant']; 
+                args.copy_counts.$attr = node.getAttribute(attr);
+            END;
+        END;
+
         # KCLS-specific stuff; needs to change
         args.mattype = xml.findnodes('//*[@tag="998"]/*[@code="d"]').textContent;
         args.kcls_cn = xml.findnodes('//*[@tag="092" or @tag="099"]/*').textContent;
index ddafce5..a46784b 100644 (file)
@@ -76,7 +76,7 @@
                                             <td class='result_table_pic_header'
                                                 width="78" nowrap="nowrap" valign="top">
                                                 [% ident = attrs.isbn_clean || attrs.upc; IF ident; %]
-                                                <a href="[% ctx.opac_root %]/record/[% rec.bre.id _ propagator %]"><img alt="Image of item"
+                                                <a href="[% ctx.opac_root %]/record/[% rec.id _ propagator %]"><img alt="Image of item"
                                                         name='item_jacket' class='result_table_pic' width="55"
                                                         src='[% ctx.media_prefix %]/opac/extras/ac/jacket/small/[% ident %]' /></a><br />
                                                 [% END %]
@@ -86,7 +86,7 @@
                                                 valign="top">
                                                 <div class="bold">
                                                     <a title="[% attrs.title %]" name='item_title'
-                                                        href="[% ctx.opac_root %]/record/[% rec.bre.id _ propagator %]"
+                                                        href="[% ctx.opac_root %]/record/[% rec.id _ propagator %]"
                                                         class='search_link'>[% attrs.title %]</a>
                                                 </div>
                                                 <span style="font-size:11px;">
                                                     </table>
                                                     <div>
                                                         [% l('[_1] of [quant,_2,copy,copies] available',
-                                                            rec.copy_counts.available, rec.copy_counts.visible) %]
+                                                            attrs.copy_counts.available, attrs.copy_counts.count) # XXX s/count/nshadow/ ?
+                                                            #rec.copy_counts.available, rec.copy_counts.visible) 
+                                                        %]
                                                     </div>
                                                 </span>
                                                 <div class="hide_me">
                                                 <div style="width:250px;text-align:left;">
                                                     <div style="float:right;">
                                                         <div class="results_aux_utils opac-auto-010"><a
-                                                                href="[% ctx.opac_root %]/place_hold[% propagator; propagator.length > 1 ? "&" : ""; %]hold_target=[% rec.bre.id %]&hold_type=T" name="place_hold_link" class="no-dec"><img
+                                                                href="[% ctx.opac_root %]/place_hold[% propagator; propagator.length > 1 ? "&" : ""; %]hold_target=[% rec.id %]&hold_type=T" name="place_hold_link" class="no-dec"><img
                                                                 src="[% ctx.media_prefix %]/images/green_check.png"
                                                                 alt="place hold" /><span
                                                                     style="position:relative;top:-3px;left:3px;">Place Hold</span></a>
                                                         </div>
                                                         <div class="results_aux_utils opac-auto-011">
-                                                            [%  operation = ctx.mylist.grep(rec.bre.id).size ? "delete" : "add";
+                                                            [%  operation = ctx.mylist.grep(rec.id).size ? "delete" : "add";
                                                                 label = (operation == "add") ? "Add to" : "Remove from"; %]
                                                             <form action="[% ctx.opac_root %]/mylist/[% operation %]" method="POST">
-                                                                <input type="hidden" name="record" value="[% rec.bre.id %]" />
+                                                                <input type="hidden" name="record" value="[% rec.id %]" />
                                                             <div style="position:absolute;">
                                                                 <div style="position:relative;top:5px; left: 25px;">
                                                                     <input type="submit" title="[% l(label _ ' my list') %]" value="[% l(label _ ' my list') %]" class="subtle-button" />