Skip to content

Commit 8c83a83

Browse files
committed
reduce caching time when showing unsynchronized epochs/slots
1 parent 5bea0b7 commit 8c83a83

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

handlers/epochs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
100100
dbCnt := len(dbEpochs)
101101
epochCount := uint64(0)
102102
allFinalized := true
103+
allSynchronized := true
103104
for epochIdx := int64(firstEpoch); epochIdx >= 0 && epochCount < epochLimit; epochIdx-- {
104105
epoch := uint64(epochIdx)
105106
finalized := finalizedEpoch >= epochIdx
@@ -132,6 +133,8 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
132133
epochData.TotalVoteParticipation = float64(dbEpoch.VotedTotal) * 100.0 / float64(dbEpoch.Eligible)
133134
}
134135
epochData.EthTransactionCount = dbEpoch.EthTransactionCount
136+
} else {
137+
allSynchronized = false
135138
}
136139
pageData.Epochs = append(pageData.Epochs, epochData)
137140
epochCount++
@@ -141,7 +144,9 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
141144
pageData.LastEpoch = firstEpoch - pageData.EpochCount + 1
142145

143146
var cacheTimeout time.Duration
144-
if allFinalized {
147+
if !allSynchronized {
148+
cacheTimeout = 30 * time.Second
149+
} else if allFinalized {
145150
cacheTimeout = 30 * time.Minute
146151
} else if firstEpoch+2 < uint64(currentEpoch) {
147152
cacheTimeout = 10 * time.Minute

handlers/slots.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
130130
dbCnt := len(dbSlots)
131131
blockCount := uint64(0)
132132
allFinalized := true
133+
allSynchronized := true
133134
isFirstPage := firstSlot >= currentSlot
134135
openForks := map[int][]byte{}
135136
maxOpenFork := 0
@@ -189,6 +190,9 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
189190
Proposer: slotAssignments[slot],
190191
ProposerName: services.GlobalBeaconService.GetValidatorName(slotAssignments[slot]),
191192
}
193+
if !slotData.Synchronized {
194+
allSynchronized = false
195+
}
192196
pageData.Slots = append(pageData.Slots, slotData)
193197
blockCount++
194198
buildSlotsPageSlotGraph(pageData, slotData, &maxOpenFork, openForks, isFirstPage)
@@ -200,7 +204,10 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
200204
pageData.ForkTreeWidth = (maxOpenFork * 20) + 20
201205

202206
var cacheTimeout time.Duration
203-
if allFinalized {
207+
208+
if !allSynchronized {
209+
cacheTimeout = 30 * time.Second
210+
} else if allFinalized {
204211
cacheTimeout = 30 * time.Minute
205212
} else if firstEpoch < uint64(currentEpoch) {
206213
cacheTimeout = 10 * time.Minute

0 commit comments

Comments
 (0)