Fix race condition in team functions (#3268)
This commit is contained in:
parent
edce41ae65
commit
c64924682e
|
@ -102,11 +102,12 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.NumRepos++
|
if _, err = e.Incr("num_repos").ID(t.ID).Update(new(Team)); err != nil {
|
||||||
if _, err = e.ID(t.ID).Cols("num_repos").Update(t); err != nil {
|
|
||||||
return fmt.Errorf("update team: %v", err)
|
return fmt.Errorf("update team: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.NumRepos++
|
||||||
|
|
||||||
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
|
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
|
||||||
return fmt.Errorf("recalculateAccesses: %v", err)
|
return fmt.Errorf("recalculateAccesses: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -488,8 +489,6 @@ func AddTeamMember(team *Team, userID int64) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get team and its repositories.
|
// Get team and its repositories.
|
||||||
team.NumMembers++
|
|
||||||
|
|
||||||
if err := team.GetRepositories(); err != nil {
|
if err := team.GetRepositories(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -506,10 +505,12 @@ func AddTeamMember(team *Team, userID int64) error {
|
||||||
TeamID: team.ID,
|
TeamID: team.ID,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
team.NumMembers++
|
||||||
|
|
||||||
// Give access to team repositories.
|
// Give access to team repositories.
|
||||||
for _, repo := range team.Repos {
|
for _, repo := range team.Repos {
|
||||||
if err := repo.recalculateTeamAccesses(sess, 0); err != nil {
|
if err := repo.recalculateTeamAccesses(sess, 0); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user