diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go index e0b75d5adf..3a0815f7a5 100644 --- a/models/issues/issue_search.go +++ b/models/issues/issue_search.go @@ -183,14 +183,13 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) { } func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) { - 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}))) - } else if len(opts.ProjectIDs) > 0 { // specific project - sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). - In("project_issue.project_id", opts.ProjectIDs) + if len(opts.ProjectIDs) > 0 { // specific project + if opts.ProjectIDs[0] == 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}))) + } else { + sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). + In("project_issue.project_id", opts.ProjectIDs) + } } // opts.ProjectID == 0 means all projects, // do not need to apply any condition diff --git a/modules/indexer/issues/dboptions.go b/modules/indexer/issues/dboptions.go index c1f454eeee..c97ba545be 100644 --- a/modules/indexer/issues/dboptions.go +++ b/modules/indexer/issues/dboptions.go @@ -38,10 +38,10 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp searchOpt.MilestoneIDs = opts.MilestoneIDs } - if opts.ProjectID > 0 { - searchOpt.ProjectID = optional.Some(opts.ProjectID) - } else if opts.ProjectID == -1 { // FIXME: this is inconsistent from other places - searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0) + if len(opts.ProjectIDs) == 1 && opts.ProjectIDs[0] == db.NoConditionID { + searchOpt.ProjectIDs = []int64{0} + } else { + searchOpt.ProjectIDs = opts.ProjectIDs // Those issues with no project(projectid==0) } if opts.AssigneeID > 0 {