Fix race condition in team functions (#3268)

This commit is contained in:
Ethan Koenig 2017-12-30 22:08:08 -05:00 committed by Lunny Xiao
parent edce41ae65
commit c64924682e

View File

@ -102,11 +102,12 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
return err
}
t.NumRepos++
if _, err = e.ID(t.ID).Cols("num_repos").Update(t); err != nil {
if _, err = e.Incr("num_repos").ID(t.ID).Update(new(Team)); err != nil {
return fmt.Errorf("update team: %v", err)
}
t.NumRepos++
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
return fmt.Errorf("recalculateAccesses: %v", err)
}
@ -488,8 +489,6 @@ func AddTeamMember(team *Team, userID int64) error {
}
// Get team and its repositories.
team.NumMembers++
if err := team.GetRepositories(); err != nil {
return err
}
@ -506,10 +505,12 @@ func AddTeamMember(team *Team, userID int64) error {
TeamID: team.ID,
}); err != nil {
return err
} else if _, err := sess.ID(team.ID).Update(team); err != nil {
} else if _, err := sess.Incr("num_members").ID(team.ID).Update(new(Team)); err != nil {
return err
}
team.NumMembers++
// Give access to team repositories.
for _, repo := range team.Repos {
if err := repo.recalculateTeamAccesses(sess, 0); err != nil {