From 32548ad82cbc7d99f7e8ea9d4fab3195beb8e88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 19 May 2026 22:33:18 +0200 Subject: [PATCH] Use .modify() for conditional FOR UPDATE SKIP LOCKED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- .../stitcher/getDeferredStitchableEntities.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/catalog-backend/src/database/operations/stitcher/getDeferredStitchableEntities.ts b/plugins/catalog-backend/src/database/operations/stitcher/getDeferredStitchableEntities.ts index 20c2d863eb..7535d6e5ed 100644 --- a/plugins/catalog-backend/src/database/operations/stitcher/getDeferredStitchableEntities.ts +++ b/plugins/catalog-backend/src/database/operations/stitcher/getDeferredStitchableEntities.ts @@ -61,20 +61,16 @@ export async function getDeferredStitchableEntities(options: { // are released after the SELECT auto-commits, and another worker can // claim the same rows before the UPDATE runs. const run = async (tx: Knex | Knex.Transaction) => { - let itemsQuery = tx('stitch_queue').select( - 'entity_ref', - 'next_stitch_at', - 'stitch_ticket', - ); - - if (useLocking) { - itemsQuery = itemsQuery.forUpdate().skipLocked(); - } - - const items = await itemsQuery + const items = await tx('stitch_queue') + .select('entity_ref', 'next_stitch_at', 'stitch_ticket') .where('next_stitch_at', '<=', tx.fn.now()) .orderBy('next_stitch_at', 'asc') - .limit(batchSize); + .limit(batchSize) + .modify(qb => { + if (useLocking) { + qb.forUpdate().skipLocked(); + } + }); if (!items.length) { return [];