Skip to content

Commit ba448d2

Browse files
committed
fix go-gitea#4479: add issue/pull id to search
1 parent b5326a4 commit ba448d2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

modules/indexer/issues/db/db.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
5151
// The notification is defined in modules, but it's using lots of things should be in services.
5252

5353
cond := builder.NewCond()
54-
5554
if options.Keyword != "" {
5655
repoCond := builder.In("repo_id", options.RepoIDs)
5756
if len(options.RepoIDs) == 1 {
5857
repoCond = builder.Eq{"repo_id": options.RepoIDs[0]}
5958
}
6059
subQuery := builder.Select("id").From("issue").Where(repoCond)
6160

61+
var issueCond builder.Cond
62+
issueCond = nil
63+
if options.Index.Has() {
64+
issueCond = builder.Eq{"issue.index": options.Keyword}
65+
}
6266
cond = builder.Or(
6367
db.BuildCaseInsensitiveLike("issue.name", options.Keyword),
6468
db.BuildCaseInsensitiveLike("issue.content", options.Keyword),
@@ -70,6 +74,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
7074
db.BuildCaseInsensitiveLike("content", options.Keyword),
7175
)),
7276
),
77+
issueCond,
7378
)
7479
}
7580

modules/indexer/issues/indexer.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"runtime/pprof"
11+
"strconv"
1112
"sync/atomic"
1213
"time"
1314

@@ -283,9 +284,13 @@ const (
283284
func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, error) {
284285
indexer := *globalIndexer.Load()
285286

286-
if opts.Keyword == "" {
287+
issueIndex, err := strconv.Atoi(opts.Keyword)
288+
if err == nil {
289+
opts.Index = optional.Option[int64]{int64(issueIndex)}
290+
}
291+
if opts.Keyword == "" || opts.Index.Has() {
287292
// This is a conservative shortcut.
288-
// If the keyword is empty, db has better (at least not worse) performance to filter issues.
293+
// If the keyword is empty or an integer, db has better (at least not worse) performance to filter issues.
289294
// When the keyword is empty, it tends to listing rather than searching issues.
290295
// So if the user creates an issue and list issues immediately, the issue may not be listed because the indexer needs time to index the issue.
291296
// Even worse, the external indexer like elastic search may not be available for a while,

modules/indexer/issues/internal/model.go

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ type SearchOptions struct {
8989

9090
MilestoneIDs []int64 // milestones the issues have
9191

92+
Index optional.Option[int64] // keyword as potential issue index
93+
9294
ProjectID optional.Option[int64] // project the issues belong to
9395
ProjectColumnID optional.Option[int64] // project column the issues belong to
9496

0 commit comments

Comments
 (0)