diff --git a/models/org_team.go b/models/org_team.go index 1e3bc27071d..c667cfb8e23 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -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 {