diff --git a/crates/database/src/fee_policies.rs b/crates/database/src/fee_policies.rs index 9679a6c3f0..2dc2b796ba 100644 --- a/crates/database/src/fee_policies.rs +++ b/crates/database/src/fee_policies.rs @@ -63,22 +63,22 @@ pub async fn fetch_all( return Ok(HashMap::new()); } - let mut query_builder = QueryBuilder::new("SELECT * FROM fee_policies WHERE "); + let mut query_builder = QueryBuilder::new("SELECT * FROM fee_policies fp INNER JOIN (VALUES "); for (i, (auction_id, order_uid)) in keys_filter.iter().enumerate() { if i > 0 { - query_builder.push(" OR "); + query_builder.push(", "); } query_builder .push("(") - .push("auction_id = ") - .push_bind(auction_id) - .push(" AND ") - .push("order_uid = ") .push_bind(order_uid) + .push(", ") + .push_bind(auction_id) .push(")"); } + query_builder.push(") AS vals(order_uid, auction_id) "); + query_builder.push("ON (fp.order_uid, fp.auction_id) = (vals.order_uid, vals.auction_id) "); - query_builder.push(" ORDER BY application_order"); + query_builder.push("ORDER BY fp.application_order"); let query = query_builder.build_query_as::(); let rows = query.fetch_all(ex).await?; diff --git a/crates/database/src/order_execution.rs b/crates/database/src/order_execution.rs index 11eb9f5ba1..18d81a7cbc 100644 --- a/crates/database/src/order_execution.rs +++ b/crates/database/src/order_execution.rs @@ -55,22 +55,25 @@ pub async fn executed_protocol_fees( } let mut query_builder = QueryBuilder::new( - "SELECT order_uid, auction_id, protocol_fee_tokens, protocol_fee_amounts FROM \ - order_execution WHERE ", + "SELECT oe.order_uid, oe.auction_id, oe.protocol_fee_tokens, oe.protocol_fee_amounts FROM \ + order_execution oe INNER JOIN (VALUES ", ); for (i, (auction_id, order_uid)) in keys_filter.iter().enumerate() { if i > 0 { - query_builder.push(" OR "); + query_builder.push(", "); } query_builder - .push("(order_uid = ") + .push("(") .push_bind(order_uid) - .push(" AND auction_id = ") + .push(", ") .push_bind(auction_id) .push(")"); } + query_builder.push(") AS vals(order_uid, auction_id) "); + query_builder.push("ON (oe.order_uid, oe.auction_id) = (vals.order_uid, vals.auction_id)"); + #[derive(Clone, Debug, Eq, PartialEq, sqlx::Type, sqlx::FromRow)] struct ProtocolFees { pub order_uid: OrderUid,