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

--- Comment #2 from Tomás Cohen Arazi (tcohen) <[email protected]> ---
Created attachment 206609
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=206609&action=edit
Bug 43606: Add x-koha-embed: items support to GET /biblios

This patch adds support for embedding item data (952 fields) into the
records returned by the GET /biblios list endpoint, driven by the
'x-koha-embed: items' request header. It works for all record formats
served by the endpoint (marcxml, marc-in-json, marc and text/plain).

Previously the list endpoint had no 'x-koha-embed' parameter declared, so
sending the header resulted in a 400 response, and callers that needed
items had to fetch them one biblio at a time (GET /biblios/{id}/items),
an N+1 access pattern.

Changes:
- Declare the 'x-koha-embed' header parameter (enum: items) on the
  listBiblio operation in the swagger spec
- Add embed_items/interface/patron options to print_collection. When
  embed_items is set, each element's record is obtained through
  metadata_record so items are embedded and scoped by interface
- Read the embed from the stash and pass embed_items and
  interface => 'intranet' from the biblios list controller

The items relation is already whitelisted for prefetching on
Koha::Biblios, so the framework prefetches it from the embed header and
no separate item query is issued per biblio.

Test plan:
1. Apply this patch
2. Run:
   $ ktd --shell
   k$ yarn api:bundle
   k$ prove t/db_dependent/Koha/Objects/Record/Collections.t \
            t/db_dependent/api/v1/biblios.t
=> SUCCESS: Tests pass!
3. Restart Plack and try it out:
   k$ koha-plack --restart kohadev
   Request GET /api/v1/biblios with:
   - Accept: application/marcxml+xml and no x-koha-embed header
     => no 952 fields
   - Accept: application/marcxml+xml and x-koha-embed: items
     => one 952 field per item
4. Sign off :-D

-- 
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