Skip to content

Commit 4f2532d

Browse files
committed
Improject filter search method
1 parent 1f43f8a commit 4f2532d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

models/issues/issue_search.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
user_model "code.gitea.io/gitea/models/user"
1717
"code.gitea.io/gitea/modules/container"
1818
"code.gitea.io/gitea/modules/optional"
19+
"code.gitea.io/gitea/modules/util"
1920

2021
"xorm.io/builder"
2122
"xorm.io/xorm"
@@ -196,17 +197,10 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
196197
}
197198

198199
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
200+
opts.ProjectIDs = util.RemoveValue(opts.ProjectIDs, 0)
199201
if len(opts.ProjectIDs) > 0 { // specific project
200-
var includedProjectIDs []int64
201-
for _, projectID := range opts.ProjectIDs {
202-
if projectID > 0 {
203-
includedProjectIDs = append(includedProjectIDs, projectID)
204-
}
205-
}
206-
if len(includedProjectIDs) > 0 {
207-
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
208-
In("project_issue.project_id", includedProjectIDs)
209-
}
202+
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
203+
In("project_issue.project_id", opts.ProjectIDs)
210204
}
211205
// opts.ProjectID == 0 means all projects,
212206
// do not need to apply any condition

modules/util/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,14 @@ func DiffSlice[T comparable](oldSlice, newSlice []T) (added, removed []T) {
277277
}
278278
return added, removed
279279
}
280+
281+
func RemoveValue[T comparable](a []T, target T) []T {
282+
n := 0
283+
for _, v := range a {
284+
if v != target {
285+
a[n] = v
286+
n++
287+
}
288+
}
289+
return a[:n]
290+
}

routers/web/repo/issue_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
551551
IssueIDs: nil,
552552
}
553553

554-
if projectID > 0 {
554+
if projectID != 0 {
555555
statsOpts.ProjectIDs = []int64{projectID}
556556
}
557557

0 commit comments

Comments
 (0)