0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-21 14:34:43 +02:00

Improject filter search method

This commit is contained in:
Tyrone Yeh 2025-05-07 15:24:40 +08:00
parent 1f43f8a566
commit 4f2532de42
No known key found for this signature in database
GPG Key ID: AC8B5AA00375E170
3 changed files with 16 additions and 11 deletions

View File

@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
"xorm.io/xorm"
@ -196,17 +197,10 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
}
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
opts.ProjectIDs = util.RemoveValue(opts.ProjectIDs, 0)
if len(opts.ProjectIDs) > 0 { // specific project
var includedProjectIDs []int64
for _, projectID := range opts.ProjectIDs {
if projectID > 0 {
includedProjectIDs = append(includedProjectIDs, projectID)
}
}
if len(includedProjectIDs) > 0 {
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
In("project_issue.project_id", includedProjectIDs)
}
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

View File

@ -277,3 +277,14 @@ func DiffSlice[T comparable](oldSlice, newSlice []T) (added, removed []T) {
}
return added, removed
}
func RemoveValue[T comparable](a []T, target T) []T {
n := 0
for _, v := range a {
if v != target {
a[n] = v
n++
}
}
return a[:n]
}

View File

@ -551,7 +551,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
IssueIDs: nil,
}
if projectID > 0 {
if projectID != 0 {
statsOpts.ProjectIDs = []int64{projectID}
}