Skip to content

Commit

Permalink
Fix project filter bugs (#26490) (#26558)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiCandong authored Aug 19, 2023
1 parent 1f29cfa commit 94f8696
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
19 changes: 13 additions & 6 deletions models/issues/issue_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
return sess
}

func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if opts.ProjectID > 0 { // specific project
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue").And(builder.Neq{"project_id": 0})))
}
// opts.ProjectID == 0 means all projects,
// do not need to apply any condition
return sess
}

func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if len(opts.RepoIDs) == 1 {
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
Expand Down Expand Up @@ -213,12 +225,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
sess.And(builder.Lte{"issue.updated_unix": opts.UpdatedBeforeUnix})
}

if opts.ProjectID > 0 {
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue")))
}
applyProjectCondition(sess, opts)

if opts.ProjectBoardID != 0 {
if opts.ProjectBoardID > 0 {
Expand Down
5 changes: 1 addition & 4 deletions models/issues/issue_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ func getIssueStatsChunk(opts *IssuesOptions, issueIDs []int64) (*IssueStats, err

applyMilestoneCondition(sess, opts)

if opts.ProjectID > 0 {
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
}
applyProjectCondition(sess, opts)

if opts.AssigneeID > 0 {
applyAssigneeCondition(sess, opts.AssigneeID)
Expand Down

0 comments on commit 94f8696

Please sign in to comment.