https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43606 --- Comment #11 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 208677 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208677&action=edit Bug 43606: (QA follow-up) Prefetch items when embedding in GET /biblios When x-koha-embed: items is sent, Koha::Biblio->metadata_record fetches the items of each biblio separately, so the list endpoint still issued one items query per biblio (N+1). This patch prefetches the items relationship when the embed is requested, so the items are loaded in the same query as the biblios. It also builds the print_collection parameters (embed_items, interface) once and reuses them across the output formats, instead of repeating the hash in every branch. There are no functional changes to the output. Benchmark (200 biblios x 5 items each, marcxml, embed_items + intranet, one process per run, local KTD, identical output in both cases): | Rows | Variant | Queries | Time | Peak RSS | |------|----------------|---------|--------|----------| | 50 | no prefetch | 51 | 0.236s | 273.3 MB | | 50 | prefetch items | 1 | 0.182s | 273.5 MB | | 200 | no prefetch | 201 | 0.775s | 309.5 MB | | 200 | prefetch items | 1 | 0.533s | 310.0 MB | Queries go from N+1 to 1, time drops by about 25-30%, and memory is unchanged (+0.1%). Test plan: 1. Apply this patch and rebuild/restart (yarn build; restart_all) 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/biblios.t => SUCCESS: Tests pass! 3. Compare the query count with and without the items prefetch using DBIC_TRACE=1 against GET /api/v1/biblios with 'x-koha-embed: items' and Accept: application/marcxml+xml 4. Sign off :-D Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.