Skip to content

Commit 35d1b0f

Browse files
committed
fixup! Break ties of PreferDistinct submissions with equal counts
Less pushing
1 parent 5c0aec1 commit 35d1b0f

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

opsqueue/src/consumer/strategy.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ impl Strategy {
7979
let ffi_is_not_reserved =
8080
"opsqueue_is_reserved(chunks.submission_id, chunks.chunk_index) = FALSE";
8181
match self {
82-
Oldest => qb
83-
.push("SELECT * FROM chunks")
84-
.push(format!(" WHERE {ffi_is_not_reserved}"))
85-
.push(" ORDER BY submission_id ASC"),
86-
Newest => qb
87-
.push("SELECT * FROM chunks")
88-
.push(format!(" WHERE {ffi_is_not_reserved}"))
89-
.push(" ORDER BY submission_id DESC"),
82+
Oldest => qb.push(format!(
83+
"SELECT * FROM chunks WHERE {ffi_is_not_reserved} ORDER BY submission_id ASC"
84+
)),
85+
Newest => qb.push(format!(
86+
"SELECT * FROM chunks WHERE {ffi_is_not_reserved} ORDER BY submission_id DESC"
87+
)),
9088
Random => Self::push_random_order_query(qb, "*", "chunks", Some(ffi_is_not_reserved)),
9189
PreferDistinct { .. } => {
9290
// Unique submission IDs from the underlying strategy.
@@ -121,16 +119,19 @@ impl Strategy {
121119
PreferDistinct { .. } => {
122120
let mut meta_keys_iter = self.meta_keys();
123121
let meta_keys: Vec<&str> = meta_keys_iter.by_ref().collect();
124-
if meta_keys.is_empty() {
125-
panic!("`PreferDistinct` always yields at least one meta key.")
126-
}
122+
assert!(
123+
!meta_keys.is_empty(),
124+
"`PreferDistinct` always yields at least one meta key."
125+
);
127126
let underlying = meta_keys_iter.take();
128127

129128
// Unique submission IDs from the underlying strategy. Note how
130129
// we also keep the row number from the underlying query, this
131130
// is used as a tie-breaker if metadata counts are equal.
132-
let qb = qb.push("WITH inner AS NOT MATERIALIZED (");
133-
qb.push("SELECT submission_id, ROW_NUMBER() OVER () as underlying_row FROM ( ");
131+
let qb = qb.push(
132+
"WITH inner AS NOT MATERIALIZED (
133+
SELECT submission_id, ROW_NUMBER() OVER () as underlying_row FROM ( ",
134+
);
134135
let qb = underlying.build_query_snippet_returning_submission_ids(qb);
135136
qb.push(" ))");
136137

0 commit comments

Comments
 (0)