Skip to content

Commit

Permalink
(NOBIDS) limit resultset of validators and withdrawals to 10000 for p…
Browse files Browse the repository at this point in the history
…erformance-reasons (#2513)
  • Loading branch information
guybrush authored Aug 30, 2023
1 parent 394a44e commit e238720
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions handlers/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func parseValidatorsDataQueryParams(r *http.Request) (*ValidatorsDataQueryParams
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
return nil, err
}
if start > 10000 {
// limit offset to 10000, otherwise the query will be too slow
start = 10000
}

length, err := strconv.ParseInt(q.Get("length"), 10, 64)
if err != nil {
Expand Down Expand Up @@ -364,6 +368,13 @@ func ValidatorsData(w http.ResponseWriter, r *http.Request) {
countFiltered = countTotal
}

if countTotal > 10000 {
countTotal = 10000
}
if countFiltered > 10000 {
countFiltered = 10000
}

data := &types.DataTableResponse{
Draw: dataQuery.Draw,
RecordsTotal: countTotal,
Expand Down
21 changes: 21 additions & 0 deletions handlers/withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func WithdrawalsData(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
}
if start > 10000 {
start = 10000
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
Expand Down Expand Up @@ -194,6 +197,13 @@ func WithdrawalsTableData(draw uint64, search string, length, start uint64, orde
}
}

if filteredCount > 10000 {
filteredCount = 10000
}
if withdrawalCount > 10000 {
withdrawalCount = 10000
}

data := &types.DataTableResponse{
Draw: draw,
RecordsTotal: withdrawalCount,
Expand Down Expand Up @@ -224,6 +234,10 @@ func BLSChangeData(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
}
if start > 10000 {
// limit offset to 10000, otherwise the query will be too slow
start = 10000
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
Expand Down Expand Up @@ -338,6 +352,13 @@ func BLSTableData(draw uint64, search string, length, start uint64, orderBy, ord
}
}

if totalCount > 10000 {
totalCount = 10000
}
if filteredCount > 10000 {
filteredCount = 10000
}

data := &types.DataTableResponse{
Draw: draw,
RecordsTotal: totalCount,
Expand Down
1 change: 1 addition & 0 deletions templates/validators.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-table"></i> Validators Overview</h1
</nav>
</div>
</div>
<h6 class="my-2">This table only shows the first 10000 validators of the resultset for the given sorting and filters.</h6>
<div class="card">
<div class="card-body px-0 py-2">
<div class="table-responsive pt-2">
Expand Down
4 changes: 2 additions & 2 deletions templates/withdrawals.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ <h2 class="h4 my-3">
{{ template "withdrawalChart" . }}
</div>
<div class="my-3">
<h6 class="my-2">This table displays partial and full withdrawals.</h6>
<h6 class="my-2">This table displays partial and full withdrawals. Only the first 10000 entries of the resultset are shown.</h6>
<div class="card">
<div class="card-body px-0 py-2">
<div class="table-responsive pt-2">
Expand All @@ -239,7 +239,7 @@ <h2 class="h4 my-3">
<span class="nav-text">Address Changes (BLS)</span>
</h2>
<div class="my-3">
<h6 class="my-2">This table displays the BLS address changes from <span class="monospace">0x00</span> credentials to <span class="monospace">0x01</span>.</h6>
<h6 class="my-2">This table displays the BLS address changes from <span class="monospace">0x00</span> credentials to <span class="monospace">0x01</span>. Only the first 10000 entries of the resultset are shown.</h6>
<div class="card">
<div class="card-body px-0 py-2">
<div class="table-responsive pt-2">
Expand Down

0 comments on commit e238720

Please sign in to comment.