loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix project filter bugs (#26490)

related: #26012

### Bugs
1. missing project filter on the issue page.

https://github.com/go-gitea/gitea/blob/1e76a824bcd71acd59cdfb2c4547806bc34b3d86/modules/indexer/issues/dboptions.go#L11-L15
3. incorrect SQL condition: some issue does not belong to a project but
exists on the project_issue table.

https://github.com/go-gitea/gitea/blob/f5dbac9d36f1678b928bee04e85fbd045c725698/models/issues/issue_search.go#L233

### Before:

![before](https://github.com/go-gitea/gitea/assets/50507092/1dcde39e-3e2f-4151-b2c6-4d67bf493c2f)

### After:

![after](https://github.com/go-gitea/gitea/assets/50507092/badfb81f-056d-4a2f-9838-1cba9c15768d)

---------

Co-authored-by: Giteabot <teabot@gitea.io>

authored by

CaiCandong
Giteabot
and committed by
GitHub
0e74fc4a 7f8028e5

+18 -10
+13 -6
models/issues/issue_search.go
··· 168 168 return sess 169 169 } 170 170 171 + func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { 172 + if opts.ProjectID > 0 { // specific project 173 + sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). 174 + And("project_issue.project_id=?", opts.ProjectID) 175 + } else if opts.ProjectID == db.NoConditionID { // show those that are in no project 176 + sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue").And(builder.Neq{"project_id": 0}))) 177 + } 178 + // opts.ProjectID == 0 means all projects, 179 + // do not need to apply any condition 180 + return sess 181 + } 182 + 171 183 func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { 172 184 if len(opts.RepoIDs) == 1 { 173 185 opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]} ··· 226 238 sess.And(builder.Lte{"issue.updated_unix": opts.UpdatedBeforeUnix}) 227 239 } 228 240 229 - if opts.ProjectID > 0 { 230 - sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). 231 - And("project_issue.project_id=?", opts.ProjectID) 232 - } else if opts.ProjectID == db.NoConditionID { // show those that are in no project 233 - sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue"))) 234 - } 241 + applyProjectCondition(sess, opts) 235 242 236 243 if opts.ProjectBoardID != 0 { 237 244 if opts.ProjectBoardID > 0 {
+1 -4
models/issues/issue_stats.go
··· 133 133 134 134 applyMilestoneCondition(sess, opts) 135 135 136 - if opts.ProjectID > 0 { 137 - sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). 138 - And("project_issue.project_id=?", opts.ProjectID) 139 - } 136 + applyProjectCondition(sess, opts) 140 137 141 138 if opts.AssigneeID > 0 { 142 139 applyAssigneeCondition(sess, opts.AssigneeID)
+4
modules/indexer/issues/dboptions.go
··· 17 17 IsClosed: opts.IsClosed, 18 18 } 19 19 20 + if opts.ProjectID != 0 { 21 + searchOpt.ProjectID = &opts.ProjectID 22 + } 23 + 20 24 if len(opts.LabelIDs) == 1 && opts.LabelIDs[0] == 0 { 21 25 searchOpt.NoLabelOnly = true 22 26 } else {