From: Lebbeous Fogle-Weekley Date: Tue, 16 Aug 2011 20:43:21 +0000 (-0400) Subject: Reduce code duplication; use $U->bib_container_items_via_search() now ... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c5f10c0f458bfd95260167ba3953ddd9c86aef3f;p=evergreen%2Fequinox.git Reduce code duplication; use $U->bib_container_items_via_search() now ... ... that it exists. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 055a2bb20a..fc345ec722 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -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; diff --git a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 index 17f2f8dfc2..8a5a7cba17 100644 --- a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 @@ -165,7 +165,7 @@ [% 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 %]