From 034cd17498cbee76b0044edfc9fd850407031630 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 22 Jul 2026 00:36:22 -0400 Subject: [PATCH] fix(artwork): index artwork_queue in dequeue order The previous leading retry_at range column forced a temp B-tree sort of the whole eligible set on every DequeueBatch; ordering the index by (priority DESC, enqueued_at) lets scans stop after the batch size. --- db/migrations/20260722023032_add_artwork_tables.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/migrations/20260722023032_add_artwork_tables.sql b/db/migrations/20260722023032_add_artwork_tables.sql index 94e0ebe5f..7133b71ce 100644 --- a/db/migrations/20260722023032_add_artwork_tables.sql +++ b/db/migrations/20260722023032_add_artwork_tables.sql @@ -33,7 +33,8 @@ CREATE TABLE artwork_queue ( enqueued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (item_kind, item_id, image_type) ) WITHOUT ROWID; -CREATE INDEX ix_artwork_queue_drain ON artwork_queue(retry_at, priority, enqueued_at); +-- Ordered to match DequeueBatch (priority DESC, enqueued_at) so drains stop after n rows; retry_at makes it covering. +CREATE INDEX ix_artwork_queue_drain ON artwork_queue(priority DESC, enqueued_at, retry_at); -- +goose Down DROP TABLE artwork_queue;