From ec9b43ba167ffc37d3abd6d7174588e18a10dd59 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 22 Aug 2022 02:46:56 +0100 Subject: [PATCH] Remove calls to load Mirrors in user.Dashboard (#20855) (#20897) Backport #20855 Whilst looking at #20840 I noticed that the Mirrors data doesn't appear to be being used therefore we can remove this and in fact none of the related code is used elsewhere so it can also be removed. Related #20840 Related #20804 Signed-off-by: Andrew Thornton Signed-off-by: Andrew Thornton Signed-off-by: Andrew Thornton Co-authored-by: Lunny Xiao --- models/repo/mirror.go | 53 ---------------------------------------- routers/web/user/home.go | 33 ------------------------- 2 files changed, 86 deletions(-) diff --git a/models/repo/mirror.go b/models/repo/mirror.go index e94bbda2c..6a95bc48c 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -8,7 +8,6 @@ package repo import ( "context" "errors" - "fmt" "time" "code.gitea.io/gitea/models/db" @@ -121,55 +120,3 @@ func InsertMirror(ctx context.Context, mirror *Mirror) error { _, err := db.GetEngine(ctx).Insert(mirror) return err } - -// MirrorRepositoryList contains the mirror repositories -type MirrorRepositoryList []*Repository - -func (repos MirrorRepositoryList) loadAttributes(ctx context.Context) error { - if len(repos) == 0 { - return nil - } - - // Load mirrors. - repoIDs := make([]int64, 0, len(repos)) - for i := range repos { - if !repos[i].IsMirror { - continue - } - - repoIDs = append(repoIDs, repos[i].ID) - } - mirrors := make([]*Mirror, 0, len(repoIDs)) - if err := db.GetEngine(ctx). - Where("id > 0"). - In("repo_id", repoIDs). - Find(&mirrors); err != nil { - return fmt.Errorf("find mirrors: %v", err) - } - - set := make(map[int64]*Mirror) - for i := range mirrors { - set[mirrors[i].RepoID] = mirrors[i] - } - for i := range repos { - repos[i].Mirror = set[repos[i].ID] - if repos[i].Mirror != nil { - repos[i].Mirror.Repo = repos[i] - } - } - return nil -} - -// LoadAttributes loads the attributes for the given MirrorRepositoryList -func (repos MirrorRepositoryList) LoadAttributes() error { - return repos.loadAttributes(db.DefaultContext) -} - -// GetUserMirrorRepositories returns a list of mirror repositories of given user. -func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { - repos := make([]*Repository, 0, 10) - return repos, db.GetEngine(db.DefaultContext). - Where("owner_id = ?", userID). - And("is_mirror = ?", true). - Find(&repos) -} diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 1c93972b9..b18ba8e6e 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -100,39 +100,6 @@ func Dashboard(ctx *context.Context) { } var err error - var mirrors []*repo_model.Repository - if ctxUser.IsOrganization() { - var env organization.AccessibleReposEnvironment - if ctx.Org.Team != nil { - env = organization.OrgFromUser(ctxUser).AccessibleTeamReposEnv(ctx.Org.Team) - } else { - env, err = organization.AccessibleReposEnv(ctx, organization.OrgFromUser(ctxUser), ctx.Doer.ID) - if err != nil { - ctx.ServerError("AccessibleReposEnv", err) - return - } - } - mirrors, err = env.MirrorRepos() - if err != nil { - ctx.ServerError("env.MirrorRepos", err) - return - } - } else { - mirrors, err = repo_model.GetUserMirrorRepositories(ctxUser.ID) - if err != nil { - ctx.ServerError("GetUserMirrorRepositories", err) - return - } - } - ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum - - if err := repo_model.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil { - ctx.ServerError("MirrorRepositoryList.LoadAttributes", err) - return - } - ctx.Data["MirrorCount"] = len(mirrors) - ctx.Data["Mirrors"] = mirrors - ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{ RequestedUser: ctxUser, RequestedTeam: ctx.Org.Team,