From d74a7efb60f94a4b8e6e5f65332f94f1be31b761 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 13 Mar 2023 20:31:41 +0900 Subject: [PATCH] Use context for `RepositoryList.LoadAttributes` (#23435) --- models/repo/repo_list.go | 10 +++------- routers/api/v1/user/repo.go | 2 +- routers/web/user/notification.go | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index d9cd905a19..92b9c15b4b 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -62,7 +62,8 @@ func RepositoryListOfMap(repoMap map[int64]*Repository) RepositoryList { return RepositoryList(ValuesRepository(repoMap)) } -func (repos RepositoryList) loadAttributes(ctx context.Context) error { +// LoadAttributes loads the attributes for the given RepositoryList +func (repos RepositoryList) LoadAttributes(ctx context.Context) error { if len(repos) == 0 { return nil } @@ -107,11 +108,6 @@ func (repos RepositoryList) loadAttributes(ctx context.Context) error { return nil } -// LoadAttributes loads the attributes for the given RepositoryList -func (repos RepositoryList) LoadAttributes() error { - return repos.loadAttributes(db.DefaultContext) -} - // SearchRepoOptions holds the search options type SearchRepoOptions struct { db.ListOptions @@ -547,7 +543,7 @@ func SearchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c } if loadAttributes { - if err := repos.loadAttributes(ctx); err != nil { + if err := repos.LoadAttributes(ctx); err != nil { return nil, 0, fmt.Errorf("LoadAttributes: %w", err) } } diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index dcb14780a7..7a8978cc4e 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -31,7 +31,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { return } - if err := repos.LoadAttributes(); err != nil { + if err := repos.LoadAttributes(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "RepositoryList.LoadAttributes", err) return } diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index e96b3dd27a..e12b41e649 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -117,7 +117,7 @@ func getNotifications(ctx *context.Context) { return } notifications = notifications.Without(failures) - if err := repos.LoadAttributes(); err != nil { // TODO + if err := repos.LoadAttributes(ctx); err != nil { ctx.ServerError("LoadAttributes", err) return }