Skip to content

Commit e5c6b62

Browse files
authored
perf: explicitly cast char(n) types in tap receipts table queries (#1022)
* perf: explicitly cast char(n) types in tap receipts table queries Signed-off-by: Tomás Migone <tomas@edgeandnode.com> * fix: address pr feedback Signed-off-by: Tomás Migone <tomas@edgeandnode.com> --------- Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
1 parent a0b9979 commit e5c6b62

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

crates/tap-agent/src/agent/sender_allocation.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,11 @@ impl DatabaseInteractions for SenderAllocationState<Horizon> {
967967
FROM
968968
tap_horizon_receipts_invalid
969969
WHERE
970-
collection_id = $1
971-
AND service_provider = $2
972-
AND payer = $3
973-
AND data_service = $4
974-
AND signer_address IN (SELECT unnest($5::text[]))
970+
collection_id = $1::char(64)
971+
AND service_provider = $2::char(40)
972+
AND payer = $3::char(40)
973+
AND data_service = $4::char(40)
974+
AND signer_address = ANY($5::char(40)[])
975975
"#,
976976
)
977977
// self.allocation_id is already a CollectionId in Horizon state
@@ -1026,12 +1026,12 @@ impl DatabaseInteractions for SenderAllocationState<Horizon> {
10261026
FROM
10271027
tap_horizon_receipts
10281028
WHERE
1029-
collection_id = $1
1030-
AND service_provider = $2
1031-
AND payer = $3
1032-
AND data_service = $4
1029+
collection_id = $1::char(64)
1030+
AND service_provider = $2::char(40)
1031+
AND payer = $3::char(40)
1032+
AND data_service = $4::char(40)
10331033
AND id <= $5
1034-
AND signer_address IN (SELECT unnest($6::text[]))
1034+
AND signer_address = ANY($6::char(40)[])
10351035
AND timestamp_ns > $7
10361036
"#,
10371037
)

crates/tap-agent/src/tap/context/rav.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
3636
async fn last_rav(&self) -> Result<Option<tap_graph::v2::SignedRav>, Self::AdapterError> {
3737
let row = sqlx::query(
3838
r#"
39-
SELECT
39+
SELECT
4040
signature,
4141
collection_id,
4242
payer,
@@ -46,11 +46,11 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
4646
value_aggregate,
4747
metadata
4848
FROM tap_horizon_ravs
49-
WHERE
50-
collection_id = $1
51-
AND payer = $2
52-
AND data_service = $3
53-
AND service_provider = $4
49+
WHERE
50+
collection_id = $1::char(64)
51+
AND payer = $2::char(40)
52+
AND data_service = $3::char(40)
53+
AND service_provider = $4::char(40)
5454
"#,
5555
)
5656
.bind(CollectionId::from(self.allocation_id).encode_hex())

crates/tap-agent/src/tap/context/receipt.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
107107

108108
let records = sqlx::query(
109109
r#"
110-
SELECT
110+
SELECT
111111
id,
112112
signature,
113113
collection_id,
@@ -119,11 +119,11 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
119119
value
120120
FROM tap_horizon_receipts
121121
WHERE
122-
collection_id = $1
123-
AND payer = $2
124-
AND data_service = $3
125-
AND service_provider = $4
126-
AND signer_address IN (SELECT unnest($5::text[]))
122+
collection_id = $1::char(64)
123+
AND payer = $2::char(40)
124+
AND data_service = $3::char(40)
125+
AND service_provider = $4::char(40)
126+
AND signer_address = ANY($5::char(40)[])
127127
AND $6::numrange @> timestamp_ns
128128
ORDER BY timestamp_ns ASC
129129
LIMIT $7
@@ -291,12 +291,12 @@ impl ReceiptDelete for TapAgentContext<Horizon> {
291291
r#"
292292
DELETE FROM tap_horizon_receipts
293293
WHERE
294-
collection_id = $1
295-
AND signer_address IN (SELECT unnest($2::text[]))
294+
collection_id = $1::char(64)
295+
AND signer_address = ANY($2::char(40)[])
296296
AND $3::numrange @> timestamp_ns
297-
AND payer = $4
298-
AND data_service = $5
299-
AND service_provider = $6
297+
AND payer = $4::char(40)
298+
AND data_service = $5::char(40)
299+
AND service_provider = $6::char(40)
300300
"#,
301301
)
302302
.bind(CollectionId::from(self.allocation_id).encode_hex())

0 commit comments

Comments
 (0)