Skip to content

Commit 0df1406

Browse files
committed
fix(exporter): add batching for status updates
1 parent af2ca0a commit 0df1406

File tree

1 file changed

+17
-4
lines changed
  • backend/pkg/exporter/db

1 file changed

+17
-4
lines changed

backend/pkg/exporter/db/db.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"database/sql"
77
"encoding/base64"
88
"fmt"
9+
"github.com/sirupsen/logrus"
910

1011
"regexp"
1112
"sort"
@@ -716,12 +717,24 @@ func SaveValidators(epoch uint64, validators []*types.Validator, client rpc.Clie
716717
}
717718

718719
log.Infof("processing validator updates for %d status entry", len(validatorStatusUpdateMap))
720+
const batchSize = 1000
721+
719722
for status, validators := range validatorStatusUpdateMap {
720723
log.Infof("updating validator status to %s for %d validators", status, len(validators))
721-
_, err := validatorStatusUpdateStmt.Exec(status, pq.Array(validators))
722-
if err != nil {
723-
log.Error(err, "error updating validator status", 0)
724-
return fmt.Errorf("error updating validator status: %w", err)
724+
725+
for i := 0; i < len(validators); i += batchSize {
726+
end := i + batchSize
727+
if end > len(validators) {
728+
end = len(validators)
729+
}
730+
731+
logrus.Infof("applying update batch from index %v to %v", i, end)
732+
batch := validators[i:end]
733+
_, err := validatorStatusUpdateStmt.Exec(status, pq.Array(batch))
734+
if err != nil {
735+
log.Error(err, "error updating validator status", 0)
736+
return fmt.Errorf("error updating validator status: %w", err)
737+
}
725738
}
726739
}
727740

0 commit comments

Comments
 (0)