Skip to content

Commit

Permalink
feat: added chunk support for badger db (#1616)
Browse files Browse the repository at this point in the history
* added chunk support for badger db

* lint
  • Loading branch information
omerlavanet authored Aug 8, 2024
1 parent e942fcd commit 19d66a1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion protocol/rpcprovider/rewardserver/reward_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
pairingtypes "github.com/lavanet/lava/v2/x/pairing/types"
)

const keySeparator = "."
const (
keySeparator = "."
batchSize = 1000
)

type DB interface {
Key() string
Expand Down Expand Up @@ -77,6 +80,20 @@ func (rs *RewardDB) BatchSave(rewardEntities []*RewardEntity) (err error) {

err = db.BatchSave(rewards)
if err != nil {
if len(rewards) > batchSize {
// possible rewards is too big, try to save it in chunks
for i := 0; i < len(rewards); i += batchSize {
end := i + batchSize
if len(rewards) < i+batchSize {
end = len(rewards)
}
chunk := rewards[i:end]
err = db.BatchSave(chunk)
if err != nil {
return err
}
}
}
return err
}
}
Expand Down

0 comments on commit 19d66a1

Please sign in to comment.