Penultimate round of db.DefaultContext
refactor (#27414)
Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
50166d1f7c
commit
ebe803e514
136 changed files with 428 additions and 421 deletions
|
@ -277,8 +277,8 @@ func UpdateRepoStats(ctx context.Context, id int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func updateUserStarNumbers(users []user_model.User) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func updateUserStarNumbers(ctx context.Context, users []user_model.User) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -294,19 +294,19 @@ func updateUserStarNumbers(users []user_model.User) error {
|
|||
}
|
||||
|
||||
// DoctorUserStarNum recalculate Stars number for all user
|
||||
func DoctorUserStarNum() (err error) {
|
||||
func DoctorUserStarNum(ctx context.Context) (err error) {
|
||||
const batchSize = 100
|
||||
|
||||
for start := 0; ; start += batchSize {
|
||||
users := make([]user_model.User, 0, batchSize)
|
||||
if err = db.GetEngine(db.DefaultContext).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
||||
if err = db.GetEngine(ctx).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if err = updateUserStarNumbers(users); err != nil {
|
||||
if err = updateUserStarNumbers(ctx, users); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue