Skip to content

Commit

Permalink
Convert before-time/after-time filters for transactions endpoint to r…
Browse files Browse the repository at this point in the history
…ounds (major performance boost/avoid excessive query timeouts.
  • Loading branch information
gmalouf committed Jan 4, 2025
1 parent a81204f commit 9eda006
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,15 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
}
if !tf.BeforeTime.IsZero() {
convertedTime := tf.BeforeTime.In(time.UTC)
whereParts = append(whereParts, fmt.Sprintf("h.realtime < $%d", partNumber))
whereParts = append(whereParts, fmt.Sprintf("t.round <= ("+
"SELECT round from block_header WHERE realtime < $%d ORDER BY realtime DESC LIMIT 1)", partNumber))
whereArgs = append(whereArgs, convertedTime)
partNumber++
}
if !tf.AfterTime.IsZero() {
convertedTime := tf.AfterTime.In(time.UTC)
whereParts = append(whereParts, fmt.Sprintf("h.realtime > $%d", partNumber))
whereParts = append(whereParts, fmt.Sprintf("t.round >= ("+
"SELECT round from block_header WHERE realtime > $%d ORDER BY realtime ASC LIMIT 1)", partNumber))
whereArgs = append(whereArgs, convertedTime)
partNumber++
}
Expand Down

0 comments on commit 9eda006

Please sign in to comment.