Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter getBlobbers and getValidators for is_killed and is_shutdown #2316

Merged
merged 15 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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