Skip to content

Commit

Permalink
Merge pull request #2316 from 0chain/filter_getblobbers
Browse files Browse the repository at this point in the history
Filter getBlobbers and getValidators for is_killed and is_shutdown
  • Loading branch information
Kishan-Dhakan committed May 4, 2023
2 parents 9dbb892 + d1e46b4 commit 69be8f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 15 additions & 8 deletions code/go/0chain.net/smartcontract/dbs/event/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ func (edb *EventDb) GetBlobbers(limit common2.Pagination) ([]Blobber, error) {
var blobbers []Blobber
result := edb.Store.Get().
Preload("Rewards").
Model(&Blobber{}).Offset(limit.Offset).Limit(limit.Limit).Order(clause.OrderByColumn{
Column: clause.Column{Name: "capacity"},
Desc: limit.IsDescending,
}).Find(&blobbers)
Model(&Blobber{}).Offset(limit.Offset).
Where("is_killed = ? AND is_shutdown = ?", false, false).
Limit(limit.Limit).
Order(clause.OrderByColumn{
Column: clause.Column{Name: "capacity"},
Desc: limit.IsDescending,
}).Find(&blobbers)

return blobbers, result.Error
}
Expand All @@ -98,10 +101,13 @@ func (edb *EventDb) GetActiveBlobbers(limit common2.Pagination) ([]Blobber, erro
result := edb.Store.Get().
Preload("Rewards").
Model(&Blobber{}).Offset(limit.Offset).
Where("last_health_check > ?", common.ToTime(now).Add(-ActiveBlobbersTimeLimit).Unix()).Limit(limit.Limit).Order(clause.OrderByColumn{
Column: clause.Column{Name: "capacity"},
Desc: limit.IsDescending,
}).Find(&blobbers)
Where("last_health_check > ? AND is_killed = ? AND is_shutdown = ?",
common.ToTime(now).Add(-ActiveBlobbersTimeLimit).Unix(), false, false).
Limit(limit.Limit).
Order(clause.OrderByColumn{
Column: clause.Column{Name: "capacity"},
Desc: limit.IsDescending,
}).Find(&blobbers)
return blobbers, result.Error
}

Expand All @@ -111,6 +117,7 @@ func (edb *EventDb) GetBlobbersByRank(limit common2.Pagination) ([]string, error
result := edb.Store.Get().
Model(&Blobber{}).
Select("id").
Where("is_killed = ? AND is_shutdown = ?", false, false).
Offset(limit.Offset).Limit(limit.Limit).
Order(clause.OrderByColumn{
Column: clause.Column{Name: "rank_metric"},
Expand Down
8 changes: 6 additions & 2 deletions code/go/0chain.net/smartcontract/dbs/event/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (edb *EventDb) GetValidators(pg common2.Pagination) ([]Validator, error) {
result := edb.Store.Get().
Preload("Rewards").
Model(&Validator{}).
Offset(pg.Offset).Limit(pg.Limit).
Where("is_killed = ? AND is_shutdown = ?", false, false).
Offset(pg.Offset).
Limit(pg.Limit).
Order(clause.OrderByColumn{
Column: clause.Column{Name: "id"},
Desc: pg.IsDescending,
Expand All @@ -111,7 +113,9 @@ func (edb *EventDb) GetActiveValidators(pg common2.Pagination) ([]Validator, err
result := edb.Store.Get().
Preload("Rewards").
Model(&Validator{}).
Where("last_health_check > ?", common.ToTime(now).Add(-ActiveBlobbersTimeLimit).Unix()).Limit(pg.Limit).
Where("last_health_check > ? AND is_killed = ? AND is_shutdown = ?",
common.ToTime(now).Add(-ActiveBlobbersTimeLimit).Unix(), false, false).
Limit(pg.Limit).
Order(clause.OrderByColumn{
Column: clause.Column{Name: "id"},
Desc: pg.IsDescending,
Expand Down

0 comments on commit 69be8f2

Please sign in to comment.