[Bug 40577] New: Bulk biblio ES index update after auth change
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 Bug ID: 40577 Summary: Bulk biblio ES index update after auth change Change sponsored?: --- 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: domm@plix.at QA Contact: testopia@bugs.koha-community.org In C4::AuthoritiesMarc->merge, when merging two authorities (which is also called after ModAuthority), we check if there are biblios linked with the auth and if the auth data materialzied into those biblios needs update. If we do have a "trivial" update of the biblio (lines 1787ff), see below, we index each biblio on its own: if ( !$update && $reindex_if_needed && $syspref_include_see_from ) { my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); $indexer->index_records( $biblio->biblionumber, "specialUpdate", "biblioserver" ); } This will create one background job per biblio. But we could easily just create on background job for all those modifications, which should improve performance. I'm proposing a very small change, where instead of calling indexer->index_records, we push $biblio->biblionumber on an array. And after looping through all the biblios, we create one index job using that array. If there is some consensus that that's a good idea, I can implement it and write a test plan... -- 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=40577 --- Comment #1 from Thomas Klausner <domm@plix.at> --- Created attachment 196129 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=196129&action=edit Bug 40577: Bulk biblio ES index update after auth change When merging (or updating) authorities, the biblios using the auths might also be updated. If this happens, Koha used to create one background job for each biblio. If an auth is used in a lot of biblios, this creates a lot of background jobs, each to index one single biblio. This patch fixes that by collecting the affected biblios and putting all of them into one reindex background job. Test plan: * Apply the patch * run the unit test t/db_dependent/Authority/Merge.t * the test should now have 16 tests in total, with a new test #15 output like this: 1..3 ok 1 - 3 bibliographic record updated while merging two authorities ok 2 - we have only one more background job ok 3 - we have the correct biblio ids in the job to be indexed ok 15 - merge with ModBiblio only creates one indexer background job for multiple biblios ok 16 - no warnings Manual test plan (rather cumbersome): * Start KTD with ElasticSearch * Create an PERSON authority (eg "100a Test") * Create three biblios which use that authority in eg 100 * Access the DB to get the count of background jobs * `ktd --dbshell` * `select count(*) from background_jobs;` * the count should be the same as the number of biblios you created (eg 3). But whatever it is, remeber it * Edit the authority (change 100 to "Test new") * check if the change is reflected in the linked biblios (100a = "Test new") * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * should be three more than previously (eg 6) * You can use this SQL to verify that the last three jobs each contain one biblionumber (which is what we want to fix): * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299] | 2026-03-25 13:19:34 | | [2300] | 2026-03-25 13:19:34 | | [2301] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ * Now apply the patch and run restart_all * Edit the authority again, setting 100a to "Test new patched". * The biblios should change accordingly * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * This should now be only 1 more then the last time (so eg 7) * Check the details of the background jobs: * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` * The most recent entry should now contain three items in one row, and the following two should be the same as in the previous query (i.e. the old jobs from the edit before the patch) +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299, 2300, 2301] | 2026-03-25 13:29:17 | | [2300] | 2026-03-25 13:19:34 | | [2299] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ -- 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=40577 Thomas Klausner <domm@plix.at> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Patch complexity|--- |Small patch -- 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=40577 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- 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=40577 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #196129|0 |1 is obsolete| | -- 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=40577 --- Comment #2 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 196139 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=196139&action=edit Bug 40577: Bulk biblio ES index update after auth change When merging (or updating) authorities, the biblios using the auths might also be updated. If this happens, Koha used to create one background job for each biblio. If an auth is used in a lot of biblios, this creates a lot of background jobs, each to index one single biblio. This patch fixes that by collecting the affected biblios and putting all of them into one reindex background job. Test plan: * Apply the patch * run the unit test t/db_dependent/Authority/Merge.t * the test should now have 16 tests in total, with a new test #15 output like this: 1..3 ok 1 - 3 bibliographic record updated while merging two authorities ok 2 - we have only one more background job ok 3 - we have the correct biblio ids in the job to be indexed ok 15 - merge with ModBiblio only creates one indexer background job for multiple biblios ok 16 - no warnings Manual test plan (rather cumbersome): * Start KTD with ElasticSearch * Create an PERSON authority (eg "100a Test") * Create three biblios which use that authority in eg 100 * Access the DB to get the count of background jobs * `ktd --dbshell` * `select count(*) from background_jobs;` * the count should be the same as the number of biblios you created (eg 3). But whatever it is, remeber it * Edit the authority (change 100 to "Test new") * check if the change is reflected in the linked biblios (100a = "Test new") * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * should be three more than previously (eg 6) * You can use this SQL to verify that the last three jobs each contain one biblionumber (which is what we want to fix): * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299] | 2026-03-25 13:19:34 | | [2300] | 2026-03-25 13:19:34 | | [2301] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ * Now apply the patch and run restart_all * Edit the authority again, setting 100a to "Test new patched". * The biblios should change accordingly * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * This should now be only 1 more then the last time (so eg 7) * Check the details of the background jobs: * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` * The most recent entry should now contain three items in one row, and the following two should be the same as in the previous query (i.e. the old jobs from the edit before the patch) +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299, 2300, 2301] | 2026-03-25 13:29:17 | | [2300] | 2026-03-25 13:19:34 | | [2299] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- 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=40577 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paul.derscheid@lmscloud.de --- Comment #3 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Note, qa script is failing but due to the new pod_coverage check, not related in any way to the patch here. So I'd say it's ready to QA even with that failure. -- 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=40577 Thomas Klausner <domm@plix.at> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |When merging (or updating) release notes| |authorities, the | |Elasticsearch indexing of | |the linked biblios now will | |happen in one background | |job per authority instead | |of one background job per | |biblio. So an authority | |that is used in 100 biblios | |will now trigger one | |indexing background job | |with 100 biblio items | |instead of 100 background | |jobs with 1 biblio item | |each. -- 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=40577 Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |baptiste.wojtkowski@biblibr | |e.com --- Comment #4 from Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> --- Did not see your last comment @paul and asked confirmation to tuxayo, so we 3 agree on this :p All fine for me, setting PQA. -- 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=40577 Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA QA Contact|testopia@bugs.koha-communit |baptiste.wojtkowski@biblibr |y.org |e.com -- 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=40577 Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #196139|0 |1 is obsolete| | -- 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=40577 --- Comment #5 from Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> --- Created attachment 196302 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=196302&action=edit Bug 40577: Bulk biblio ES index update after auth change When merging (or updating) authorities, the biblios using the auths might also be updated. If this happens, Koha used to create one background job for each biblio. If an auth is used in a lot of biblios, this creates a lot of background jobs, each to index one single biblio. This patch fixes that by collecting the affected biblios and putting all of them into one reindex background job. Test plan: * Apply the patch * run the unit test t/db_dependent/Authority/Merge.t * the test should now have 16 tests in total, with a new test #15 output like this: 1..3 ok 1 - 3 bibliographic record updated while merging two authorities ok 2 - we have only one more background job ok 3 - we have the correct biblio ids in the job to be indexed ok 15 - merge with ModBiblio only creates one indexer background job for multiple biblios ok 16 - no warnings Manual test plan (rather cumbersome): * Start KTD with ElasticSearch * Create an PERSON authority (eg "100a Test") * Create three biblios which use that authority in eg 100 * Access the DB to get the count of background jobs * `ktd --dbshell` * `select count(*) from background_jobs;` * the count should be the same as the number of biblios you created (eg 3). But whatever it is, remeber it * Edit the authority (change 100 to "Test new") * check if the change is reflected in the linked biblios (100a = "Test new") * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * should be three more than previously (eg 6) * You can use this SQL to verify that the last three jobs each contain one biblionumber (which is what we want to fix): * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299] | 2026-03-25 13:19:34 | | [2300] | 2026-03-25 13:19:34 | | [2301] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ * Now apply the patch and run restart_all * Edit the authority again, setting 100a to "Test new patched". * The biblios should change accordingly * Check the Background jobs in the DB again: * `select count(*) from background_jobs;` * This should now be only 1 more then the last time (so eg 7) * Check the details of the background jobs: * `select json_extract(data,'$.record_ids'),enqueued_on from background_jobs order by enqueued_on desc limit 3;` * The most recent entry should now contain three items in one row, and the following two should be the same as in the previous query (i.e. the old jobs from the edit before the patch) +-----------------------------------+---------------------+ | json_extract(data,'$.record_ids') | enqueued_on | +-----------------------------------+---------------------+ | [2299, 2300, 2301] | 2026-03-25 13:29:17 | | [2300] | 2026-03-25 13:19:34 | | [2299] | 2026-03-25 13:19:34 | +-----------------------------------+---------------------+ Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> -- 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=40577 Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |domm@plix.at |ity.org | -- 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=40577 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to main Version(s)| |26.05.00 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 --- Comment #6 from Lucas Gass (lukeg) <lucas@bywatersolutions.com> --- Nice work everyone! Pushed to main for 26.05 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Bulk biblio ES index update |Bulk update Elasticsearch |after auth change |index for bibliographic | |records after authority | |change -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 Jacob O'Mara <jacob.omara@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)|26.05.00 |26.05.00,25.11.05 released in| | Status|Pushed to main |Pushed to stable -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 --- Comment #7 from Jacob O'Mara <jacob.omara@openfifth.co.uk> --- Thanks all, pushed to 25.11.x -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40577 Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wainuiwitikapark@catalyst.n | |et.nz Status|Pushed to stable |Needs documenting --- Comment #8 from Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> --- Enhancement - not backporting to 25.05 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org