Browse Source

optimization for team get repos (#953)

Lunny Xiao 3 years ago
parent
commit
7fd14bf7bd
1 changed files with 2 additions and 16 deletions
  1. 2 16
      models/org_team.go

+ 2 - 16
models/org_team.go

@@ -37,22 +37,8 @@ func (t *Team) IsMember(userID int64) bool {
37 37
 }
38 38
 
39 39
 func (t *Team) getRepositories(e Engine) (err error) {
40
-	teamRepos := make([]*TeamRepo, 0, t.NumRepos)
41
-	if err = x.
42
-		Where("team_id=?", t.ID).
43
-		Find(&teamRepos); err != nil {
44
-		return fmt.Errorf("get team-repos: %v", err)
45
-	}
46
-
47
-	t.Repos = make([]*Repository, 0, len(teamRepos))
48
-	for i := range teamRepos {
49
-		repo, err := getRepositoryByID(e, teamRepos[i].RepoID)
50
-		if err != nil {
51
-			return fmt.Errorf("getRepositoryById(%d): %v", teamRepos[i].RepoID, err)
52
-		}
53
-		t.Repos = append(t.Repos, repo)
54
-	}
55
-	return nil
40
+	return e.Join("INNER", "team_repo", "repository.id = team_repo.repo_id").
41
+		Where("team_repo.team_id=?", t.ID).Find(&t.Repos)
56 42
 }
57 43
 
58 44
 // GetRepositories returns all repositories in team of organization.