mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 01:40:36 +00:00
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:
parent
ea83c0647c
commit
dcf4b9e314
1 changed files with 70 additions and 18 deletions
|
@ -50,8 +50,25 @@ func migratePullMirrors(x *xorm.Engine) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := sess.Iterate(new(Mirror), func(_ int, bean any) error {
|
||||
m := bean.(*Mirror)
|
||||
limit := setting.Database.IterateBufferSize
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
|
||||
start := 0
|
||||
|
||||
for {
|
||||
var mirrors []Mirror
|
||||
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(mirrors) == 0 {
|
||||
break
|
||||
}
|
||||
start += len(mirrors)
|
||||
|
||||
for _, m := range mirrors {
|
||||
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -59,11 +76,20 @@ func migratePullMirrors(x *xorm.Engine) error {
|
|||
|
||||
m.RemoteAddress = remoteAddress
|
||||
|
||||
_, err = sess.ID(m.ID).Cols("remote_address").Update(m)
|
||||
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
|
||||
return err
|
||||
}); err != nil {
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
@ -83,8 +109,25 @@ func migratePushMirrors(x *xorm.Engine) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := sess.Iterate(new(PushMirror), func(_ int, bean any) error {
|
||||
m := bean.(*PushMirror)
|
||||
limit := setting.Database.IterateBufferSize
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
|
||||
start := 0
|
||||
|
||||
for {
|
||||
var mirrors []PushMirror
|
||||
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(mirrors) == 0 {
|
||||
break
|
||||
}
|
||||
start += len(mirrors)
|
||||
|
||||
for _, m := range mirrors {
|
||||
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -92,11 +135,20 @@ func migratePushMirrors(x *xorm.Engine) error {
|
|||
|
||||
m.RemoteAddress = remoteAddress
|
||||
|
||||
_, err = sess.ID(m.ID).Cols("remote_address").Update(m)
|
||||
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
|
||||
return err
|
||||
}); err != nil {
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue