Skip to content

Commit

Permalink
perf: update queries to load up v2
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Feb 12, 2025
1 parent d70e7e2 commit 50b7dc4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 53 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 12 additions & 25 deletions crates/tap-agent/src/agent/sender_accounts_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,11 @@ impl State {
FROM tap_horizon_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)
Expand Down Expand Up @@ -668,18 +662,11 @@ impl State {

let nonfinal_ravs_sender_allocations_in_db = sqlx::query!(
r#"
SELECT DISTINCT
sender_address,
(
SELECT ARRAY
(
SELECT DISTINCT allocation_id
FROM tap_horizon_ravs
WHERE sender_address = top.sender_address
AND NOT last
)
) AS allocation_id
FROM scalar_tap_ravs AS top
SELECT
payer,
ARRAY_AGG(DISTINCT allocation_id) FILTER (WHERE NOT last) AS allocation_ids
FROM tap_horizon_ravs
GROUP BY payer
"#
)
.fetch_all(&self.pgpool)
Expand All @@ -688,7 +675,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| {
Expand All @@ -698,8 +685,8 @@ impl State {
)
})
.collect::<HashSet<_>>();
let sender_id = Address::from_str(&row.sender_address)
.expect("sender_address should be a valid address");
let sender_id =
Address::from_str(&row.payer).expect("sender_address should be a valid address");

// Accumulate allocations for the sender
unfinalized_sender_allocations_map
Expand Down

0 comments on commit 50b7dc4

Please sign in to comment.