mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-15 18:08:23 -07:00
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
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user