Skip to content

Commit

Permalink
Optimize timestamp filters for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
agodnic committed Sep 9, 2024
1 parent 785f850 commit 0a2e04d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,13 @@ 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 bh.round FROM block_header bh WHERE bh.realtime < $%d ORDER BY bh.realtime DESC, bh.round 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 bh.round FROM block_header bh WHERE bh.realtime > $%d ORDER BY bh.realtime ASC, bh.round ASC LIMIT 1)", partNumber))
whereArgs = append(whereArgs, convertedTime)
partNumber++
}
Expand Down

0 comments on commit 0a2e04d

Please sign in to comment.