Fix wrong migration for email address (#27106)

On Iterate, `sess` should not be used in the closure function body.

Caused by #26952
This commit is contained in:
Lunny Xiao 2023-09-17 11:15:04 +08:00 committed by GitHub
parent ea83c0647c
commit dcf4b9e314
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,19 +50,45 @@ func migratePullMirrors(x *xorm.Engine) error {
return err return err
} }
if err := sess.Iterate(new(Mirror), func(_ int, bean any) error { limit := setting.Database.IterateBufferSize
m := bean.(*Mirror) if limit <= 0 {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin") limit = 50
if err != nil { }
start := 0
for {
var mirrors []Mirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
return err return err
} }
m.RemoteAddress = remoteAddress if len(mirrors) == 0 {
break
}
start += len(mirrors)
_, err = sess.ID(m.ID).Cols("remote_address").Update(m) for _, m := range mirrors {
return err remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin")
}); err != nil { if err != nil {
return err return err
}
m.RemoteAddress = remoteAddress
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
return err
}
}
if start%1000 == 0 { // avoid a too big transaction
if err := sess.Commit(); err != nil {
return err
}
if err := sess.Begin(); err != nil {
return err
}
}
} }
return sess.Commit() return sess.Commit()
@ -83,19 +109,45 @@ func migratePushMirrors(x *xorm.Engine) error {
return err return err
} }
if err := sess.Iterate(new(PushMirror), func(_ int, bean any) error { limit := setting.Database.IterateBufferSize
m := bean.(*PushMirror) if limit <= 0 {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName) limit = 50
if err != nil { }
start := 0
for {
var mirrors []PushMirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
return err return err
} }
m.RemoteAddress = remoteAddress if len(mirrors) == 0 {
break
}
start += len(mirrors)
_, err = sess.ID(m.ID).Cols("remote_address").Update(m) for _, m := range mirrors {
return err remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName)
}); err != nil { if err != nil {
return err return err
}
m.RemoteAddress = remoteAddress
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
return err
}
}
if start%1000 == 0 { // avoid a too big transaction
if err := sess.Commit(); err != nil {
return err
}
if err := sess.Begin(); err != nil {
return err
}
}
} }
return sess.Commit() return sess.Commit()