Skip to content

Commit 662a3c5

Browse files
authored
Merge pull request #414 from namada-net/improve-timestamp-query
improved block/timestamp/{value} endpoint
2 parents 4b21d04 + 6ff4248 commit 662a3c5

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX idx_block_timestamp;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE INDEX idx_block_timestamp ON blocks(timestamp);

webserver/src/repository/block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ impl BlockRepositoryTrait for BlockRepository {
6363
.expect("Invalid timestamp")
6464
.naive_utc();
6565

66+
let lower_bound = timestamp - chrono::Duration::seconds(60);
67+
6668
conn.interact(move |conn| {
6769
blocks::table
70+
.filter(blocks::timestamp.ge(lower_bound))
6871
.filter(blocks::timestamp.le(timestamp))
6972
.order(blocks::timestamp.desc())
7073
.select(BlockDb::as_select())

0 commit comments

Comments
 (0)