diff --git a/modules/indexer/issues/db/db.go b/modules/indexer/issues/db/db.go index 05ec548435f48..665f3c090229e 100644 --- a/modules/indexer/issues/db/db.go +++ b/modules/indexer/issues/db/db.go @@ -51,7 +51,6 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( // The notification is defined in modules, but it's using lots of things should be in services. cond := builder.NewCond() - if options.Keyword != "" { repoCond := builder.In("repo_id", options.RepoIDs) if len(options.RepoIDs) == 1 { @@ -59,6 +58,11 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( } subQuery := builder.Select("id").From("issue").Where(repoCond) + var issueCond builder.Cond + issueCond = nil + if options.Index.Has() { + issueCond = builder.Eq{"issue.index": options.Keyword} + } cond = builder.Or( db.BuildCaseInsensitiveLike("issue.name", options.Keyword), db.BuildCaseInsensitiveLike("issue.content", options.Keyword), @@ -70,6 +74,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( db.BuildCaseInsensitiveLike("content", options.Keyword), )), ), + issueCond, ) } diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 1cb86feb82c28..9f2e04bddc190 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "runtime/pprof" + "strconv" "sync/atomic" "time" @@ -283,9 +284,13 @@ const ( func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, error) { indexer := *globalIndexer.Load() - if opts.Keyword == "" { + issueIndex, err := strconv.Atoi(opts.Keyword) + if err == nil { + opts.Index = optional.Option[int64]{int64(issueIndex)} + } + if opts.Keyword == "" || opts.Index.Has() { // This is a conservative shortcut. - // If the keyword is empty, db has better (at least not worse) performance to filter issues. + // If the keyword is empty or an integer, db has better (at least not worse) performance to filter issues. // When the keyword is empty, it tends to listing rather than searching issues. // 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. // Even worse, the external indexer like elastic search may not be available for a while, diff --git a/modules/indexer/issues/internal/model.go b/modules/indexer/issues/internal/model.go index 2dfee8b72e197..cdf5d1bc29c48 100644 --- a/modules/indexer/issues/internal/model.go +++ b/modules/indexer/issues/internal/model.go @@ -89,6 +89,8 @@ type SearchOptions struct { MilestoneIDs []int64 // milestones the issues have + Index optional.Option[int64] // keyword as potential issue index + ProjectID optional.Option[int64] // project the issues belong to ProjectColumnID optional.Option[int64] // project column the issues belong to