Skip to content
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

Fix bug because of duplicated join #14454

Merged
merged 7 commits into from
Jan 26, 2021
Merged
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
9 changes: 7 additions & 2 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
}

if opts.IsArchived != util.OptionalBoolNone {
sess.Join("INNER", "repository", "issue.repo_id = repository.id").And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
6543 marked this conversation as resolved.
Show resolved Hide resolved
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
}

if opts.LabelIDs != nil {
Expand Down Expand Up @@ -1266,6 +1266,8 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
sess := x.NewSession()
defer sess.Close()

sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")

opts.setupSession(sess)

countsSlice := make([]*struct {
Expand All @@ -1292,11 +1294,12 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *User) ([]int64, error
sess := x.NewSession()
defer sess.Close()

sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")

opts.setupSession(sess)

accessCond := accessibleRepositoryCondition(user)
if err := sess.Where(accessCond).
Join("INNER", "repository", "`issue`.repo_id = `repository`.id").
Distinct("issue.repo_id").
Table("issue").
Find(&repoIDs); err != nil {
Expand All @@ -1311,6 +1314,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
sess := x.NewSession()
defer sess.Close()

sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
opts.setupSession(sess)
sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)

Expand Down Expand Up @@ -1338,6 +1342,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
}, 0, 1)

sess.Select("COUNT(issue.id) AS count").Table("issue")
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
opts.setupSession(sess)
if err := sess.Find(&countsSlice); err != nil {
return 0, fmt.Errorf("Find: %v", err)
Expand Down