Fix failing migration v67 (#5849)

Fixes #5848
This commit is contained in:
Jakub Arbet 2019-01-26 15:50:36 +01:00 committed by zeripath
parent 8510ac2687
commit a757920f4e

View file

@ -45,7 +45,7 @@ func removeStaleWatches(x *xorm.Engine) error {
AccessModeRead // 1 AccessModeRead // 1
) )
accessLevel := func(userID int64, repo *Repository) (int, error) { accessLevel := func(e *xorm.Session, userID int64, repo *Repository) (int, error) {
mode := AccessModeNone mode := AccessModeNone
if !repo.IsPrivate { if !repo.IsPrivate {
mode = AccessModeRead mode = AccessModeRead
@ -60,7 +60,7 @@ func removeStaleWatches(x *xorm.Engine) error {
} }
a := &Access{UserID: userID, RepoID: repo.ID} a := &Access{UserID: userID, RepoID: repo.ID}
if has, err := x.Get(a); !has || err != nil { if has, err := e.Get(a); !has || err != nil {
return mode, err return mode, err
} }
return a.Mode, nil return a.Mode, nil
@ -80,7 +80,7 @@ func removeStaleWatches(x *xorm.Engine) error {
} }
repoCache := make(map[int64]*Repository) repoCache := make(map[int64]*Repository)
err := x.BufferSize(setting.IterateBufferSize).Iterate(new(Watch), err := sess.BufferSize(setting.IterateBufferSize).Iterate(new(Watch),
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
watch := bean.(*Watch) watch := bean.(*Watch)
@ -89,14 +89,14 @@ func removeStaleWatches(x *xorm.Engine) error {
repo = &Repository{ repo = &Repository{
ID: watch.RepoID, ID: watch.RepoID,
} }
if _, err := x.Get(repo); err != nil { if _, err := sess.Get(repo); err != nil {
return err return err
} }
repoCache[watch.RepoID] = repo repoCache[watch.RepoID] = repo
} }
// Remove watches from now unaccessible repositories // Remove watches from now unaccessible repositories
mode, err := accessLevel(watch.UserID, repo) mode, err := accessLevel(sess, watch.UserID, repo)
if err != nil { if err != nil {
return err return err
} }
@ -117,7 +117,7 @@ func removeStaleWatches(x *xorm.Engine) error {
} }
repoCache = make(map[int64]*Repository) repoCache = make(map[int64]*Repository)
err = x.BufferSize(setting.IterateBufferSize). err = sess.BufferSize(setting.IterateBufferSize).
Distinct("issue_watch.user_id", "issue.repo_id"). Distinct("issue_watch.user_id", "issue.repo_id").
Join("INNER", "issue", "issue_watch.issue_id = issue.id"). Join("INNER", "issue", "issue_watch.issue_id = issue.id").
Where("issue_watch.is_watching = ?", true). Where("issue_watch.is_watching = ?", true).
@ -130,14 +130,14 @@ func removeStaleWatches(x *xorm.Engine) error {
repo = &Repository{ repo = &Repository{
ID: watch.RepoID, ID: watch.RepoID,
} }
if _, err := x.Get(repo); err != nil { if _, err := sess.Get(repo); err != nil {
return err return err
} }
repoCache[watch.RepoID] = repo repoCache[watch.RepoID] = repo
} }
// Remove issue watches from now unaccssible repositories // Remove issue watches from now unaccssible repositories
mode, err := accessLevel(watch.UserID, repo) mode, err := accessLevel(sess, watch.UserID, repo)
if err != nil { if err != nil {
return err return err
} }