https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42878
--- Comment #1 from Martin Renvoize (ashimema) <[email protected]> --- Created attachment 200641 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200641&action=edit Bug 42878: Batch the available-item check in ES marc_records_to_documents Previously, the marc_records_to_documents method performed a per-record COUNT query to check if a biblionumber had any available items. For a batch of N records, this resulted in N separate database queries: SELECT COUNT(*) FROM items WHERE biblionumber=? AND onloan IS NULL AND itemlost=0 This commit optimizes the approach by: 1. Before the per-record loop (for BIBLIOS index only), collecting all biblionumbers from the batch of records. 2. Running a single grouped query to fetch biblionumbers that have at least one available item: SELECT DISTINCT biblionumber FROM items WHERE biblionumber IN (...) AND onloan IS NULL AND itemlost=0 3. Building a hash %has_available mapping biblionumber => 1 for fast lookups. 4. In the per-record loop, replacing the per-record COUNT query with a simple hash lookup. The semantics are preserved identically: - Records with no biblionumber field (missing or empty) do not get an 'available' key, exactly as before. - Records with a biblionumber but no available items get available => \0. - Records with at least one available item get available => \1. For large batches, this can reduce database queries from N to 1. Test plan: Run the existing Elasticsearch tests to verify all available-item tests pass. The new batch test verifies that multiple records in one call are correctly evaluated for availability. -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
