Skip to content

Commit d3aa497

Browse files
lunny6543lafriks
authored
Fix bug because of duplicated join (#14454)
* Fix bug because of duplicated join * Move join into setupsession * Fix bug * Fix bug Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv>
1 parent a598877 commit d3aa497

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

models/issue.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
12101210
}
12111211

12121212
if opts.IsArchived != util.OptionalBoolNone {
1213-
sess.Join("INNER", "repository", "issue.repo_id = repository.id").And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
1213+
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
12141214
}
12151215

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

1269+
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
1270+
12691271
opts.setupSession(sess)
12701272

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

1297+
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
1298+
12951299
opts.setupSession(sess)
12961300

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

1317+
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
13141318
opts.setupSession(sess)
13151319
sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)
13161320

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

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

0 commit comments

Comments
 (0)