Reduce code duplication; use $U->bib_container_items_via_search() now ...
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 16 Aug 2011 20:43:21 +0000 (16:43 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 31 Aug 2011 17:26:11 +0000 (13:26 -0400)
... that it exists.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/web/templates/default/opac/myopac/lists.tt2

index 055a2bb..fc345ec 100644 (file)
@@ -1246,53 +1246,23 @@ sub load_myopac_bookbags {
             ($sorter ? " sort($sorter)" : ""),
             ($modifier ? "#$modifier" : "")
         );
-        my $results = $U->simplereq(
-            "open-ils.search", "open-ils.search.biblio.multiclass.query",
-            {}, $query  # XXX we need to limit the number of records per bbag
-        );
-
-        # now we have record ids, but we need the cbrebi objects too
-        my $record_id_list = [ map { pop @$_ } @{$results->{ids}} ];
-
-        # We're done with this bookbag if it has no items
-        unless (@$record_id_list) {
-            $bookbag->items([]);
-            next;
-        }
 
-        my $items = $e->search_container_biblio_record_entry_bucket_item([
-            {
-                "target_biblio_record_entry" => $record_id_list,
-                "bucket" => $bookbag->id
-            }, {
-                flesh => 1,
-                flesh_fields => {"cbrebi" => ["notes"]}
-            }
-        ]) or do {
-            $self->apache->log->warn(
-                "retrieving cbrebi, got " . $e->die_event->{textcode}
-            );
-            return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
-        };
+        # XXX we need to limit the number of records per bbag; use third arg
+        # of bib_container_items_via_search() i think.
+        my $items = $U->bib_container_items_via_search($bookbag->id, $query)
+            or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
 
-        # Put all the bucket's items in the order that search returned them in.
-        my %ordering_hash = map { $_->target_biblio_record_entry, $_ } @$items;
-        my @ordered_items = map { $ordering_hash{$_} } @$record_id_list;
-        $bookbag->items(\@ordered_items);
-    }
+        # Maybe save a little memory by creating only one XML::LibXML::Document
+        # instance for each record, even if record is repeated across bookbags.
 
-    # Get unique record IDs over the set of all fetched bookbags.
-    # We'll need to fetch their marcxml.
-    my %rec_ids = ();
-    foreach my $bbag (@{$ctx->{bookbags}}) {
-        foreach my $rec_id (
-            map { $_->target_biblio_record_entry } @{$bbag->items}
-        ) {
-            $rec_ids{$rec_id} = 1;
+        foreach my $rec (map { $_->target_biblio_record_entry } @$items) {
+            next if $ctx->{bookbags_marc_xml}{$rec->id};
+            $ctx->{bookbags_marc_xml}{$rec->id} =
+                (new XML::LibXML)->parse_string($rec->marc);
         }
-    }
 
-    $ctx->{bookbags_marc_xml} = $self->fetch_marc_xml_by_id([keys %rec_ids]);
+        $bookbag->items($items);
+    }
 
     $e->rollback;
     return Apache2::Const::OK;
index 17f2f8d..8a5a7cb 100644 (file)
                     </td></tr>
                     [% END %]
                     [% FOR item IN bbag.items;
-                        rec_id = item.target_biblio_record_entry;
+                        rec_id = item.target_biblio_record_entry.id;
                         attrs = {marc_xml => ctx.bookbags_marc_xml.$rec_id};
                         PROCESS get_marc_attrs args=attrs %]
                     <tr class="bookbag-item-row">