Skip to content

Commit 10f90a0

Browse files
authored
Merge pull request #896 from gobitfly/BEDS-519/fix-rewards-query
(BEDS-519) DA: more efficient rewards query
2 parents 20d7cb4 + 5155221 commit 10f90a0

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

backend/pkg/api/data_access/vdb_rewards.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
106106
LeftJoin(goqu.L("blocks b"), goqu.On(goqu.L("v.validator_index = b.proposer AND b.status = '1'"))).
107107
LeftJoin(goqu.L("execution_payloads ep"), goqu.On(goqu.L("ep.block_hash = b.exec_block_hash"))).
108108
LeftJoin(
109-
goqu.Dialect("postgres").
109+
goqu.Lateral(goqu.Dialect("postgres").
110110
From("relays_blocks").
111111
Select(
112112
goqu.L("exec_block_hash"),
113113
goqu.MAX("value").As("value")).
114-
GroupBy("exec_block_hash").As("rb"),
114+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
115+
GroupBy("exec_block_hash")).As("rb"),
115116
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
116117
)
117118

@@ -561,12 +562,13 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
561562
LeftJoin(goqu.L("blocks b"), goqu.On(goqu.L("v.validator_index = b.proposer AND b.status = '1'"))).
562563
LeftJoin(goqu.L("execution_payloads ep"), goqu.On(goqu.L("ep.block_hash = b.exec_block_hash"))).
563564
LeftJoin(
564-
goqu.Dialect("postgres").
565+
goqu.Lateral(goqu.Dialect("postgres").
565566
From("relays_blocks").
566567
Select(
567568
goqu.L("exec_block_hash"),
568569
goqu.MAX("value").As("value")).
569-
GroupBy("exec_block_hash").As("rb"),
570+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
571+
GroupBy("exec_block_hash")).As("rb"),
570572
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
571573
).
572574
Where(goqu.L("b.epoch = ?", epoch))
@@ -736,12 +738,13 @@ func (d *DataAccessService) GetValidatorDashboardRewardsChart(ctx context.Contex
736738
LeftJoin(goqu.L("blocks b"), goqu.On(goqu.L("v.validator_index = b.proposer AND b.status = '1'"))).
737739
LeftJoin(goqu.L("execution_payloads ep"), goqu.On(goqu.L("ep.block_hash = b.exec_block_hash"))).
738740
LeftJoin(
739-
goqu.Dialect("postgres").
741+
goqu.Lateral(goqu.Dialect("postgres").
740742
From("relays_blocks").
741743
Select(
742744
goqu.L("exec_block_hash"),
743745
goqu.MAX("value").As("value")).
744-
GroupBy("exec_block_hash").As("rb"),
746+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
747+
GroupBy("exec_block_hash")).As("rb"),
745748
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
746749
).
747750
Where(goqu.L("b.epoch >= ?", startEpoch))
@@ -987,12 +990,13 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das
987990
From(goqu.L("blocks b")).
988991
LeftJoin(goqu.L("execution_payloads ep"), goqu.On(goqu.L("ep.block_hash = b.exec_block_hash"))).
989992
LeftJoin(
990-
goqu.Dialect("postgres").
993+
goqu.Lateral(goqu.Dialect("postgres").
991994
From("relays_blocks").
992995
Select(
993996
goqu.L("exec_block_hash"),
994997
goqu.MAX("value").As("value")).
995-
GroupBy("exec_block_hash").As("rb"),
998+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
999+
GroupBy("exec_block_hash")).As("rb"),
9961000
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
9971001
).
9981002
Where(goqu.L("b.epoch = ?", epoch)).

backend/pkg/api/data_access/vdb_summary.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ func (d *DataAccessService) GetValidatorDashboardSummary(ctx context.Context, da
191191
From(goqu.L("blocks b")).
192192
LeftJoin(goqu.L("execution_payloads ep"), goqu.On(goqu.L("ep.block_hash = b.exec_block_hash"))).
193193
LeftJoin(
194-
goqu.Dialect("postgres").
194+
goqu.Lateral(goqu.Dialect("postgres").
195195
From("relays_blocks").
196196
Select(
197197
goqu.L("exec_block_hash"),
198198
goqu.MAX("value").As("value")).
199-
GroupBy("exec_block_hash").As("rb"),
199+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
200+
GroupBy("exec_block_hash")).As("rb"),
200201
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
201202
).
202203
Where(goqu.L("b.epoch >= ? AND b.epoch <= ? AND b.status = '1'", epochMin, epochMax)).
@@ -829,12 +830,13 @@ func (d *DataAccessService) internal_getElClAPR(ctx context.Context, dashboardId
829830
From(goqu.L("blocks AS b")).
830831
LeftJoin(goqu.L("execution_payloads AS ep"), goqu.On(goqu.L("b.exec_block_hash = ep.block_hash"))).
831832
LeftJoin(
832-
goqu.Dialect("postgres").
833+
goqu.Lateral(goqu.Dialect("postgres").
833834
From("relays_blocks").
834835
Select(
835836
goqu.L("exec_block_hash"),
836837
goqu.MAX("value").As("value")).
837-
GroupBy("exec_block_hash").As("rb"),
838+
Where(goqu.L("relays_blocks.exec_block_hash = b.exec_block_hash")).
839+
GroupBy("exec_block_hash")).As("rb"),
838840
goqu.On(goqu.L("rb.exec_block_hash = b.exec_block_hash")),
839841
).
840842
Where(goqu.L("b.status = '1'"))

0 commit comments

Comments
 (0)