($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;