Skip to content

Commit

Permalink
reduce caching time when showing unsynchronized epochs/slots
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 24, 2023
1 parent 5bea0b7 commit 8c83a83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion handlers/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
dbCnt := len(dbEpochs)
epochCount := uint64(0)
allFinalized := true
allSynchronized := true
for epochIdx := int64(firstEpoch); epochIdx >= 0 && epochCount < epochLimit; epochIdx-- {
epoch := uint64(epochIdx)
finalized := finalizedEpoch >= epochIdx
Expand Down Expand Up @@ -132,6 +133,8 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
epochData.TotalVoteParticipation = float64(dbEpoch.VotedTotal) * 100.0 / float64(dbEpoch.Eligible)
}
epochData.EthTransactionCount = dbEpoch.EthTransactionCount
} else {
allSynchronized = false
}
pageData.Epochs = append(pageData.Epochs, epochData)
epochCount++
Expand All @@ -141,7 +144,9 @@ func buildEpochsPageData(firstEpoch uint64, pageSize uint64) (*models.EpochsPage
pageData.LastEpoch = firstEpoch - pageData.EpochCount + 1

var cacheTimeout time.Duration
if allFinalized {
if !allSynchronized {
cacheTimeout = 30 * time.Second
} else if allFinalized {
cacheTimeout = 30 * time.Minute
} else if firstEpoch+2 < uint64(currentEpoch) {
cacheTimeout = 10 * time.Minute
Expand Down
9 changes: 8 additions & 1 deletion handlers/slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
dbCnt := len(dbSlots)
blockCount := uint64(0)
allFinalized := true
allSynchronized := true
isFirstPage := firstSlot >= currentSlot
openForks := map[int][]byte{}
maxOpenFork := 0
Expand Down Expand Up @@ -189,6 +190,9 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
Proposer: slotAssignments[slot],
ProposerName: services.GlobalBeaconService.GetValidatorName(slotAssignments[slot]),
}
if !slotData.Synchronized {
allSynchronized = false
}
pageData.Slots = append(pageData.Slots, slotData)
blockCount++
buildSlotsPageSlotGraph(pageData, slotData, &maxOpenFork, openForks, isFirstPage)
Expand All @@ -200,7 +204,10 @@ func buildSlotsPageData(firstSlot uint64, pageSize uint64) (*models.SlotsPageDat
pageData.ForkTreeWidth = (maxOpenFork * 20) + 20

var cacheTimeout time.Duration
if allFinalized {

if !allSynchronized {
cacheTimeout = 30 * time.Second
} else if allFinalized {
cacheTimeout = 30 * time.Minute
} else if firstEpoch < uint64(currentEpoch) {
cacheTimeout = 10 * time.Minute
Expand Down

0 comments on commit 8c83a83

Please sign in to comment.