[Bug 42879] New: Avoid per-record plugin lookup in ES marc_records_to_documents
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 Bug ID: 42879 Summary: Avoid per-record plugin lookup in ES marc_records_to_documents Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Searching - Elasticsearch Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Target Milestone: --- marc_records_to_documents invokes Koha::Plugins->call('elasticsearch_to_document', ...) once per record. Each call discovers the plugins implementing the hook, which runs a query against plugin_data -- even when no plugin implements the hook or plugins are disabled. In a batch reindex this is one extra query per record purely to discover there is nothing to call. The set of implementing plugins is constant for the batch. Resolve it once (or short-circuit when plugins are disabled / none implement the hook), then dispatch per record. Test plan: 1. prove t/db_dependent/Koha/SearchEngine/Elasticsearch.t 2. With a plugin implementing elasticsearch_to_document, confirm the hook still fires for every record. 3. Count DB statements during a batch reindex before/after. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |42881 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42881 [Bug 42881] Improve Elasticsearch Indexing performance -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Trivial patch Status|NEW |Needs Signoff -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 200642 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200642&action=edit Bug 42879: Avoid per-record plugin lookup in ES marc_records_to_documents Before this patch, Koha::Plugins->call('elasticsearch_to_document', ...) was invoked once per record inside the foreach loop in marc_records_to_documents(). Each call internally invokes GetPlugins() to discover which plugins implement the hook, which queries the plugin_data table. This discovery query runs N times for N records, even when zero plugins implement the hook or plugins are disabled. After this patch, the elasticsearch_to_document plugins are resolved once per batch (before the per-record loop) using Koha::Plugins->new()->GetPlugins() with a method filter. The result is cached in a boolean flag. The per-record Koha::Plugins->call() is now guarded by that flag, so: 1. When plugins are disabled (Koha::Plugins->new returns undef), no lookup occurs. 2. When no plugins implement the hook, GetPlugins() is called once (not N times). 3. When plugins exist, the same call path is used, preserving all existing behavior. Variant implemented: SAFE minimal approach - Compute a single boolean flag $has_elasticsearch_plugins before the loop - Only invoke Koha::Plugins->call() when the flag is true - This avoids per-record plugin discovery for the common (no-plugin) case - The proven call path is preserved when plugins are present Test plan: 1. Verify marc_records_to_documents produces correct document output (existing tests) 2. Run prove t/db_dependent/Koha/SearchEngine/Elasticsearch.t to ensure all subtests pass 3. Verify with KTD: index a batch of records and confirm correct Elasticsearch documents 4. Optionally: enable a test plugin with elasticsearch_to_document hook and verify it is still invoked -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42879 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nick@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org