https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43606

--- Comment #7 from Lisette Scheer <[email protected]> ---
Created attachment 206945
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=206945&action=edit
Bug 43606: Avoid redundant queries when embedding items

When embedding items into a record, Koha::Filter::MARC::EmbedItems calls
Koha::Item->as_marc_field on every item. Each call resolved the MARC
structure on its own and, to get the framework code, accessed
$item->biblio, which materialized the biblio object from the database
once per biblio being processed.

This patch avoids that redundant work:

- Koha::Item->as_marc_field now accepts an optional 'tagslib' parameter
  (a MARC structure as returned by C4::Biblio::GetMarcStructure). When
  passed, it is used instead of resolving the structure internally
- Koha::Filter::MARC::EmbedItems resolves the structure once per record,
  using the frameworkcode already provided by metadata_record in its
  options (so no biblio object is materialized), and passes it to each
  as_marc_field call

There are no functional changes; the embedded output is identical.

Test plan:
1. Apply this patch
2. Run:
   $ ktd --shell
   k$ prove t/db_dependent/api/v1/biblios.t t/db_dependent/Koha/Item.pm
=> SUCCESS: Tests pass!
3. Confirm the query reduction:
   k$ DBIC_TRACE=1 perl -e '
       use Koha::Biblios;
       Koha::Biblios->search( undef,
           { prefetch => [qw(biblioitem metadata items)], rows => 5 } )
         ->print_collection(
           { format => q{marcxml}, embed_items => 1, interface => q{intranet} }
);
     ' 2>&1 | grep -c "FROM \`biblio\` .*biblionumber"
=> SUCCESS: 0 (no biblio object is materialized while embedding)
4. Sign off :-D

Signed-off-by: Lisette Scheer <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to