do not reload slice if already loaded
This commit is contained in:
parent
8216a2a210
commit
f6983856de
3 changed files with 10 additions and 2 deletions
|
@ -53,7 +53,9 @@ func (org *User) GetOwnerTeam() (*Team, error) {
|
|||
}
|
||||
|
||||
func (org *User) getTeams(e Engine) error {
|
||||
org.Teams = nil
|
||||
if org.Teams != nil {
|
||||
return nil
|
||||
}
|
||||
return e.
|
||||
Where("org_id=?", org.ID).
|
||||
OrderBy("CASE WHEN name LIKE '" + ownerTeamName + "' THEN '' ELSE name END").
|
||||
|
|
|
@ -88,7 +88,9 @@ func (t *Team) IsMember(userID int64) bool {
|
|||
}
|
||||
|
||||
func (t *Team) getRepositories(e Engine) error {
|
||||
t.Repos = nil
|
||||
if t.Repos != nil {
|
||||
return nil
|
||||
}
|
||||
return e.Join("INNER", "team_repo", "repository.id = team_repo.repo_id").
|
||||
Where("team_repo.team_id=?", t.ID).
|
||||
OrderBy("repository.name").
|
||||
|
|
|
@ -452,11 +452,13 @@ func TestAllRepositoriesTeams(t *testing.T) {
|
|||
repoCounts[4] = 3
|
||||
for i, team := range teams {
|
||||
assert.NoError(t, UpdateTeam(team, false), "team %d: UpdateTeam", i)
|
||||
team.Repos = nil // Reset repos to allow their reloading.
|
||||
assert.NoError(t, team.GetRepositories(), "team %d: GetRepositories", i)
|
||||
assert.Equal(t, repoCounts[i], len(team.Repos), "team %d: repo count", i)
|
||||
}
|
||||
|
||||
// Create repo and check teams repo count.
|
||||
org.Teams = nil // Reset teams to allow their reloading.
|
||||
r, err := CreateRepository(user, org, CreateRepoOptions{Name: "repo-last"})
|
||||
assert.NoError(t, err, "CreateRepository last")
|
||||
if r != nil {
|
||||
|
@ -466,6 +468,7 @@ func TestAllRepositoriesTeams(t *testing.T) {
|
|||
repoCounts[1] = 4
|
||||
repoCounts[4] = 4
|
||||
for i, team := range teams {
|
||||
team.Repos = nil // Reset repos to allow their reloading.
|
||||
assert.NoError(t, team.GetRepositories(), "team %d: GetRepositories", i)
|
||||
assert.Equal(t, repoCounts[i], len(team.Repos), "team %d: repo count", i)
|
||||
}
|
||||
|
@ -477,6 +480,7 @@ func TestAllRepositoriesTeams(t *testing.T) {
|
|||
repoCounts[3] = 2
|
||||
repoCounts[4] = 3
|
||||
for i, team := range teams {
|
||||
team.Repos = nil // Reset repos to allow their reloading.
|
||||
assert.NoError(t, team.GetRepositories(), "team %d: GetRepositories", i)
|
||||
assert.Equal(t, repoCounts[i], len(team.Repos), "team %d: repo count", i)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue