From 7074d224f36f2db21fb4b712f95733b1ae72d93b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 13 Nov 2025 09:40:00 -0500 Subject: [PATCH] Bug 41248: Add ability for real time holds queue background jobs to skip duplicate jobs It seems inefficient to rebuild the holds queue repeatedly for the same record. We should skip enqueuing BatchUpdateBiblioHoldsQueue jobs if there is already a queued job that hasn't started. Test Plan: 1) Enable real time holds queue 2) Ensure the default queue background job worker is not running 3) Set up 2 or more holds for the record 4) Alter the priority for those holds a couple times 5) Confirm only one new job is in the background_jobs table for that record. Signed-off-by: Lucas Gass --- Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm index 53b5d2b45c4..9d3842e0c82 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm @@ -19,6 +19,7 @@ use Modern::Perl; use Try::Tiny; +use Koha::BackgroundJobs; use Koha::Biblios; use Koha::Exceptions; @@ -134,6 +135,13 @@ sub enqueue { my @biblio_ids = @{ $args->{biblio_ids} }; + # If any given bib has a specific job already queued, we can skip this job. Limited to single bib jobs for performance. + @biblio_ids = grep { + Koha::BackgroundJobs->count( { type => $self->job_type, status => 'new', data => qq/{"biblio_ids":["$_"]}/ } ) + == 0 + } @biblio_ids; + return unless @biblio_ids; + $self->SUPER::enqueue( { job_size => scalar @biblio_ids, -- 2.39.5