From 6514487ea955bb2ac10e0e632714e89c72607e41 Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 4 Jan 2024 11:01:25 -0600 Subject: [PATCH] Index on queue_time for job queue, limit to 10 jobs in ID query --- src/repo/postgres.rs | 1 + .../V0010__add_queue_time_index_to_job_queue.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/repo/postgres/migrations/V0010__add_queue_time_index_to_job_queue.rs diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index fa5a5ab..3c2c189 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -1191,6 +1191,7 @@ impl QueueRepo for PostgresRepo { .and(queue_alias.field(queue).eq(queue_name)), ) .order(queue_alias.field(queue_time)) + .limit(10) .for_update() .skip_locked() .single_value(); diff --git a/src/repo/postgres/migrations/V0010__add_queue_time_index_to_job_queue.rs b/src/repo/postgres/migrations/V0010__add_queue_time_index_to_job_queue.rs new file mode 100644 index 0000000..eb092b0 --- /dev/null +++ b/src/repo/postgres/migrations/V0010__add_queue_time_index_to_job_queue.rs @@ -0,0 +1,11 @@ +use barrel::backend::Pg; +use barrel::{types, Migration}; + +pub(crate) fn migration() -> String { + let mut m = Migration::new(); + + m.inject_custom("CREATE INDEX queue_time_index ON job_queue (queue_time);"); + m.inject_custom("DROP INDEX queue_status_index;"); + + m.make::().to_string() +}