Skip to content

Commit

Permalink
Merge pull request #6 from AlgoNode/optimize-timestamp-filters
Browse files Browse the repository at this point in the history
Optimize timestamp filters for transactions
  • Loading branch information
urtho authored Sep 16, 2024
2 parents 785f850 + 0a2e04d commit 0753471
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 0753471

Please sign in to comment.