Skip to content

Use context for RepositoryList.LoadAttributes #23435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/user/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down