From bf03c5cd3240899941bbae558ac4d1d70c0094db 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. --- Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm index 4a779f4c9c6..ed6180eaf3f 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.50.1 (Apple Git-155)