1
0
Fork 0
forked from forgejo/forgejo

Add context.Context to more methods (#21546)

This PR adds a context parameter to a bunch of methods. Some helper
`xxxCtx()` methods got replaced with the normal name now.

Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
KN4CK3R 2022-11-19 09:12:33 +01:00 committed by GitHub
parent fefdb7ffd1
commit 044c754ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
148 changed files with 1411 additions and 1564 deletions

View file

@ -34,7 +34,8 @@ func (issues IssueList) getRepoIDs() []int64 {
return repoIDs.Values()
}
func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Repository, error) {
// LoadRepositories loads issues' all repositories
func (issues IssueList) LoadRepositories(ctx context.Context) ([]*repo_model.Repository, error) {
if len(issues) == 0 {
return nil, nil
}
@ -73,11 +74,6 @@ func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Rep
return repo_model.ValuesRepository(repoMaps), nil
}
// LoadRepositories loads issues' all repositories
func (issues IssueList) LoadRepositories() ([]*repo_model.Repository, error) {
return issues.loadRepositories(db.DefaultContext)
}
func (issues IssueList) getPosterIDs() []int64 {
posterIDs := make(container.Set[int64], len(issues))
for _, issue := range issues {
@ -317,7 +313,8 @@ func (issues IssueList) getPullIssueIDs() []int64 {
return ids
}
func (issues IssueList) loadPullRequests(ctx context.Context) error {
// LoadPullRequests loads pull requests
func (issues IssueList) LoadPullRequests(ctx context.Context) error {
issuesIDs := issues.getPullIssueIDs()
if len(issuesIDs) == 0 {
return nil
@ -361,7 +358,8 @@ func (issues IssueList) loadPullRequests(ctx context.Context) error {
return nil
}
func (issues IssueList) loadAttachments(ctx context.Context) (err error) {
// LoadAttachments loads attachments
func (issues IssueList) LoadAttachments(ctx context.Context) (err error) {
if len(issues) == 0 {
return nil
}
@ -513,8 +511,8 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) {
// loadAttributes loads all attributes, expect for attachments and comments
func (issues IssueList) loadAttributes(ctx context.Context) error {
if _, err := issues.loadRepositories(ctx); err != nil {
return fmt.Errorf("issue.loadAttributes: loadRepositories: %w", err)
if _, err := issues.LoadRepositories(ctx); err != nil {
return fmt.Errorf("issue.loadAttributes: LoadRepositories: %w", err)
}
if err := issues.loadPosters(ctx); err != nil {
@ -537,7 +535,7 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
return fmt.Errorf("issue.loadAttributes: loadAssignees: %w", err)
}
if err := issues.loadPullRequests(ctx); err != nil {
if err := issues.LoadPullRequests(ctx); err != nil {
return fmt.Errorf("issue.loadAttributes: loadPullRequests: %w", err)
}
@ -554,24 +552,14 @@ func (issues IssueList) LoadAttributes() error {
return issues.loadAttributes(db.DefaultContext)
}
// LoadAttachments loads attachments
func (issues IssueList) LoadAttachments() error {
return issues.loadAttachments(db.DefaultContext)
}
// LoadComments loads comments
func (issues IssueList) LoadComments() error {
return issues.loadComments(db.DefaultContext, builder.NewCond())
func (issues IssueList) LoadComments(ctx context.Context) error {
return issues.loadComments(ctx, builder.NewCond())
}
// LoadDiscussComments loads discuss comments
func (issues IssueList) LoadDiscussComments() error {
return issues.loadComments(db.DefaultContext, builder.Eq{"comment.type": CommentTypeComment})
}
// LoadPullRequests loads pull requests
func (issues IssueList) LoadPullRequests() error {
return issues.loadPullRequests(db.DefaultContext)
func (issues IssueList) LoadDiscussComments(ctx context.Context) error {
return issues.loadComments(ctx, builder.Eq{"comment.type": CommentTypeComment})
}
// GetApprovalCounts returns a map of issue ID to slice of approval counts