Skip to content

Commit e61e9a3

Browse files
authored
Fix PullRequestList.GetIssueIDs's logic (#31352)
fix a bug from #30490 `prs.GetIssueIDs()` will also be used in other places, e.g. `InvalidateCodeComments` so we should not add `if pr.Issue == nil` in it, or if `pr.Issue` is already loaded, you will not get the issueID in the results list and this is not an expected result. So this will caused a bug: before calling `InvalidateCodeComments`, all `pr.Issues` in `prs` are loaded, so `issueIDs` in this function will always be `[]`. ![image](https://github.com/go-gitea/gitea/assets/18380374/ef94d9d2-0bf9-455a-abd6-4d5e6497db7c)
1 parent bb04311 commit e61e9a3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

models/issues/pull_list.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ func (prs PullRequestList) LoadIssues(ctx context.Context) (IssueList, error) {
192192
return nil, nil
193193
}
194194

195-
// Load issues.
196-
issueIDs := prs.GetIssueIDs()
195+
// Load issues which are not loaded
196+
issueIDs := container.FilterSlice(prs, func(pr *PullRequest) (int64, bool) {
197+
return pr.IssueID, pr.Issue == nil && pr.IssueID > 0
198+
})
197199
issues := make(map[int64]*Issue, len(issueIDs))
198200
if err := db.GetEngine(ctx).
199201
In("id", issueIDs).
@@ -229,10 +231,7 @@ func (prs PullRequestList) LoadIssues(ctx context.Context) (IssueList, error) {
229231
// GetIssueIDs returns all issue ids
230232
func (prs PullRequestList) GetIssueIDs() []int64 {
231233
return container.FilterSlice(prs, func(pr *PullRequest) (int64, bool) {
232-
if pr.Issue == nil {
233-
return pr.IssueID, pr.IssueID > 0
234-
}
235-
return 0, false
234+
return pr.IssueID, pr.IssueID > 0
236235
})
237236
}
238237

0 commit comments

Comments
 (0)