From f6983856de8a534ff23affd7c09006d7195974b0 Mon Sep 17 00:00:00 2001 From: Nicolas Gourdon Date: Tue, 30 Apr 2019 22:01:16 +0200 Subject: [PATCH] do not reload slice if already loaded --- models/org.go | 4 +++- models/org_team.go | 4 +++- models/org_team_test.go | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/models/org.go b/models/org.go index b3d51f7946..e335c78e43 100644 --- a/models/org.go +++ b/models/org.go @@ -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"). diff --git a/models/org_team.go b/models/org_team.go index f88d953b90..d40387f3f1 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -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"). diff --git a/models/org_team_test.go b/models/org_team_test.go index 11db52e5f2..6960224d44 100644 --- a/models/org_team_test.go +++ b/models/org_team_test.go @@ -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) }