Skip to content

Commit

Permalink
Optimize sub-queries for assets/apps against a given address.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalouf committed Jun 6, 2024
1 parent b019536 commit 8a10650
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1799,13 +1799,28 @@ func (db *IndexerDb) buildAccountQuery(opts idb.AccountQueryOptions, countOnly b
whereArgs = append(whereArgs, *opts.AssetLT)
partNumber++
}

// We want to limit the size of the results in this query to what could actually be needed
if len(opts.GreaterThanAddress) > 0 {
aq += fmt.Sprintf(" AND addr > $%d", partNumber)
whereArgs = append(whereArgs, opts.GreaterThanAddress)
partNumber++
}

Check warning on line 1808 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1805-L1808

Added lines #L1805 - L1808 were not covered by tests
aq = "qasf AS (" + aq + ")"
withClauses = append(withClauses, aq)
}
if opts.HasAppID != 0 {
withClauses = append(withClauses, fmt.Sprintf("qapf AS (SELECT addr FROM account_app WHERE app = $%d)", partNumber))
aq := fmt.Sprintf("SELECT addr FROM account_app WHERE app = $%d", partNumber)

Check warning on line 1813 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1813

Added line #L1813 was not covered by tests
whereArgs = append(whereArgs, opts.HasAppID)
partNumber++

if len(opts.GreaterThanAddress) > 0 {
aq += fmt.Sprintf(" AND addr > $%d", partNumber)
whereArgs = append(whereArgs, opts.GreaterThanAddress)
partNumber++
}
aq = "qapf AS (" + aq + ")"
withClauses = append(withClauses, aq)

Check warning on line 1823 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1816-L1823

Added lines #L1816 - L1823 were not covered by tests
}
// filters against main account table
if len(opts.GreaterThanAddress) > 0 {
Expand Down

0 comments on commit 8a10650

Please sign in to comment.