diff --git a/.sqlx/query-fef5849dc64c15d1188d6398c93a59bfaafd9a38cf342739cdabf8b7bba073d3.json b/.sqlx/query-11a939012cce92b3c148c22f13b2e81089b7b27af2a1dd22a8c6b8da561b6ec1.json similarity index 50% rename from .sqlx/query-fef5849dc64c15d1188d6398c93a59bfaafd9a38cf342739cdabf8b7bba073d3.json rename to .sqlx/query-11a939012cce92b3c148c22f13b2e81089b7b27af2a1dd22a8c6b8da561b6ec1.json index 45046c574..2a5799903 100644 --- a/.sqlx/query-fef5849dc64c15d1188d6398c93a59bfaafd9a38cf342739cdabf8b7bba073d3.json +++ b/.sqlx/query-11a939012cce92b3c148c22f13b2e81089b7b27af2a1dd22a8c6b8da561b6ec1.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n WITH grouped AS (\n SELECT signer_address, allocation_id\n FROM scalar_tap_receipts\n GROUP BY signer_address, allocation_id\n )\n SELECT DISTINCT\n signer_address,\n (\n SELECT ARRAY\n (\n SELECT DISTINCT allocation_id\n FROM grouped\n WHERE signer_address = top.signer_address\n )\n ) AS allocation_ids\n FROM grouped AS top\n ", + "query": "\n WITH grouped AS (\n SELECT signer_address, allocation_id\n FROM scalar_tap_receipts\n GROUP BY signer_address, allocation_id\n )\n SELECT \n signer_address,\n ARRAY_AGG(allocation_id) AS allocation_ids\n FROM grouped\n GROUP BY signer_address\n ", "describe": { "columns": [ { @@ -22,5 +22,5 @@ null ] }, - "hash": "fef5849dc64c15d1188d6398c93a59bfaafd9a38cf342739cdabf8b7bba073d3" + "hash": "11a939012cce92b3c148c22f13b2e81089b7b27af2a1dd22a8c6b8da561b6ec1" } diff --git a/.sqlx/query-67c8c6323c92732bb994593223ccb4f7b9b4a4bda786542c18b404d2287e78a7.json b/.sqlx/query-67c8c6323c92732bb994593223ccb4f7b9b4a4bda786542c18b404d2287e78a7.json new file mode 100644 index 000000000..da7961da7 --- /dev/null +++ b/.sqlx/query-67c8c6323c92732bb994593223ccb4f7b9b4a4bda786542c18b404d2287e78a7.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n sender_address,\n ARRAY_AGG(DISTINCT allocation_id) FILTER (WHERE NOT last) AS allocation_ids\n FROM scalar_tap_ravs\n GROUP BY sender_address\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "sender_address", + "type_info": "Bpchar" + }, + { + "ordinal": 1, + "name": "allocation_ids", + "type_info": "BpcharArray" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + null + ] + }, + "hash": "67c8c6323c92732bb994593223ccb4f7b9b4a4bda786542c18b404d2287e78a7" +} diff --git a/.sqlx/query-8fe28629e2453852a41abd452ed519167d3f358d25aa02f306779270a084f8c3.json b/.sqlx/query-8fe28629e2453852a41abd452ed519167d3f358d25aa02f306779270a084f8c3.json deleted file mode 100644 index 0e764ac98..000000000 --- a/.sqlx/query-8fe28629e2453852a41abd452ed519167d3f358d25aa02f306779270a084f8c3.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT DISTINCT\n sender_address,\n (\n SELECT ARRAY\n (\n SELECT DISTINCT allocation_id\n FROM scalar_tap_ravs\n WHERE sender_address = top.sender_address\n AND NOT last\n )\n ) AS allocation_id\n FROM scalar_tap_ravs AS top\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "sender_address", - "type_info": "Bpchar" - }, - { - "ordinal": 1, - "name": "allocation_id", - "type_info": "BpcharArray" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - null - ] - }, - "hash": "8fe28629e2453852a41abd452ed519167d3f358d25aa02f306779270a084f8c3" -} diff --git a/crates/tap-agent/src/agent/sender_accounts_manager.rs b/crates/tap-agent/src/agent/sender_accounts_manager.rs index e1d0b46cf..46649a987 100644 --- a/crates/tap-agent/src/agent/sender_accounts_manager.rs +++ b/crates/tap-agent/src/agent/sender_accounts_manager.rs @@ -415,17 +415,11 @@ impl State { FROM scalar_tap_receipts GROUP BY signer_address, allocation_id ) - SELECT DISTINCT + SELECT signer_address, - ( - SELECT ARRAY - ( - SELECT DISTINCT allocation_id - FROM grouped - WHERE signer_address = top.signer_address - ) - ) AS allocation_ids - FROM grouped AS top + ARRAY_AGG(allocation_id) AS allocation_ids + FROM grouped + GROUP BY signer_address "# ) .fetch_all(&self.pgpool) @@ -461,18 +455,11 @@ impl State { let nonfinal_ravs_sender_allocations_in_db = sqlx::query!( r#" - SELECT DISTINCT + SELECT sender_address, - ( - SELECT ARRAY - ( - SELECT DISTINCT allocation_id - FROM scalar_tap_ravs - WHERE sender_address = top.sender_address - AND NOT last - ) - ) AS allocation_id - FROM scalar_tap_ravs AS top + ARRAY_AGG(DISTINCT allocation_id) FILTER (WHERE NOT last) AS allocation_ids + FROM scalar_tap_ravs + GROUP BY sender_address "# ) .fetch_all(&self.pgpool) @@ -481,7 +468,7 @@ impl State { for row in nonfinal_ravs_sender_allocations_in_db { let allocation_ids = row - .allocation_id + .allocation_ids .expect("all RAVs should have an allocation_id") .iter() .map(|allocation_id| { diff --git a/justfile b/justfile index af79a0fa2..386417eb6 100644 --- a/justfile +++ b/justfile @@ -34,3 +34,4 @@ psql-down: migrate: sqlx migrate run --database-url postgresql://postgres:postgres@127.0.0.1:5432 +