Skip to content

Commit

Permalink
Optimization: block stats request (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Dec 16, 2024
1 parent f3dab2c commit 7b23e6f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/storage/postgres/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func (b *Blocks) ByHash(ctx context.Context, hash []byte) (block storage.Block,
// ListWithStats -
func (b *Blocks) ListWithStats(ctx context.Context, limit, offset uint64, order sdk.SortOrder) (blocks []*storage.Block, err error) {
subQuery := b.DB().NewSelect().Model(&blocks)
subQuery = postgres.Pagination(subQuery, limit, offset, order)
subQuery = sortScope(subQuery, "block.time", order)
subQuery = limitScope(subQuery, int(limit))
subQuery = offsetScope(subQuery, int(offset))

query := b.DB().NewSelect().
ColumnExpr("block.*").
Expand All @@ -97,7 +99,7 @@ func (b *Blocks) ListWithStats(ctx context.Context, limit, offset uint64, order
TableExpr("(?) as block", subQuery).
Join("LEFT JOIN block_stats as stats ON stats.height = block.height").
Join("LEFT JOIN validator as v ON v.id = block.proposer_id")
query = sortScope(query, "block.id", order)
query = sortScope(query, "block.time", order)
err = query.Scan(ctx, &blocks)

return
Expand Down

0 comments on commit 7b23e6f

Please sign in to comment.