Skip to content

Commit 259f134

Browse files
committed
fix
1 parent a713b4c commit 259f134

File tree

14 files changed

+55
-71
lines changed

14 files changed

+55
-71
lines changed

models/issues/issue_search.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
7676
if strings.HasPrefix(sortType, ScopeSortPrefix) {
7777
scope := strings.TrimPrefix(sortType, ScopeSortPrefix)
7878
sess.Join("LEFT", "issue_label", "issue.id = issue_label.issue_id")
79-
sess.Join("LEFT", "label", "label.id = issue_label.label_id and label.name LIKE ?", scope+"/%")
80-
// Use COALESCE to make sure we sort NULL last regardless of backend DB (9223372036854775807 == max bigint)
81-
sess.OrderBy("COALESCE(label.exclusive_order, 9223372036854775807) ASC").Desc("issue.id")
79+
// "exclusive_order=0" means "no order is set", so exclude it from the JOIN criteria and then "LEFT JOIN" result is also null
80+
sess.Join("LEFT", "label", "label.id = issue_label.label_id AND label.exclusive_order <> 0 AND label.name LIKE ?", scope+"/%")
81+
// Use COALESCE to make sure we sort NULL last regardless of backend DB (2147483647 == max int)
82+
sess.OrderBy("COALESCE(label.exclusive_order, 2147483647) ASC").Desc("issue.id")
8283
return
8384
}
8485

models/issues/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type Label struct {
8787
OrgID int64 `xorm:"INDEX"`
8888
Name string
8989
Exclusive bool
90-
ExclusiveOrder int `xorm:"DEFAULT 0"`
90+
ExclusiveOrder int `xorm:"DEFAULT 0"` // 0 means no exclusive order
9191
Description string
9292
Color string `xorm:"VARCHAR(7)"`
9393
NumIssues int

models/migrations/v1_24/v319.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func AddExclusiveOrderColumnToLabelTable(x *xorm.Engine) error {
1111
type Label struct {
12-
ExclusiveOrder int64 `xorm:"DEFAULT 0"`
12+
ExclusiveOrder int `xorm:"DEFAULT 0"`
1313
}
1414

1515
return x.Sync(new(Label))

modules/indexer/issues/bleve/bleve.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package bleve
55

66
import (
77
"context"
8-
"errors"
98
"strconv"
109

1110
"code.gitea.io/gitea/modules/indexer"
@@ -287,10 +286,6 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
287286
"updated_unix"))
288287
}
289288

290-
if len(options.IssueIDs) > 0 {
291-
return nil, errors.New("options.IssueIDs is not yet supported")
292-
}
293-
294289
var indexerQuery query.Query = bleve.NewConjunctionQuery(queries...)
295290
if len(queries) == 0 {
296291
indexerQuery = bleve.NewMatchAllQuery()

modules/indexer/issues/db/db.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package db
66
import (
77
"context"
88
"strings"
9+
"sync"
910

1011
"code.gitea.io/gitea/models/db"
1112
issue_model "code.gitea.io/gitea/models/issues"
@@ -18,7 +19,7 @@ import (
1819
"xorm.io/builder"
1920
)
2021

21-
var _ internal.Indexer = &Indexer{}
22+
var _ internal.Indexer = (*Indexer)(nil)
2223

2324
// Indexer implements Indexer interface to use database's like search
2425
type Indexer struct {
@@ -29,11 +30,9 @@ func (i *Indexer) SupportedSearchModes() []indexer.SearchMode {
2930
return indexer.SearchModesExactWords()
3031
}
3132

32-
func NewIndexer() *Indexer {
33-
return &Indexer{
34-
Indexer: &inner_db.Indexer{},
35-
}
36-
}
33+
var GetIndexer = sync.OnceValue(func() *Indexer {
34+
return &Indexer{Indexer: &inner_db.Indexer{}}
35+
})
3736

3837
// Index dummy function
3938
func (i *Indexer) Index(_ context.Context, _ ...*internal.IndexerData) error {

modules/indexer/issues/db/options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
7373
ExcludedLabelNames: nil,
7474
IncludeMilestones: nil,
7575
SortType: sortType,
76-
IssueIDs: options.IssueIDs,
7776
UpdatedAfterUnix: options.UpdatedAfterUnix.Value(),
7877
UpdatedBeforeUnix: options.UpdatedBeforeUnix.Value(),
7978
PriorityRepoID: 0,

modules/indexer/issues/dboptions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ import (
1010
issues_model "code.gitea.io/gitea/models/issues"
1111
"code.gitea.io/gitea/modules/indexer/issues/internal"
1212
"code.gitea.io/gitea/modules/optional"
13+
"code.gitea.io/gitea/modules/setting"
1314
)
1415

1516
func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOptions {
17+
if opts.IssueIDs != nil {
18+
setting.PanicInDevOrTesting("Indexer SearchOptions doesn't support IssueIDs")
19+
}
1620
searchOpt := &SearchOptions{
1721
Keyword: keyword,
1822
RepoIDs: opts.RepoIDs,
1923
AllPublic: opts.AllPublic,
2024
IsPull: opts.IsPull,
2125
IsClosed: opts.IsClosed,
2226
IsArchived: opts.IsArchived,
23-
IssueIDs: opts.IssueIDs,
2427
}
2528

2629
if len(opts.LabelIDs) == 1 && opts.LabelIDs[0] == 0 {

modules/indexer/issues/elasticsearch/elasticsearch.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package elasticsearch
55

66
import (
77
"context"
8-
"errors"
98
"strconv"
109
"strings"
1110

@@ -201,10 +200,6 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
201200
}
202201
}
203202

204-
if len(options.IssueIDs) > 0 {
205-
return nil, errors.New("options.IssueIDs is not yet supported")
206-
}
207-
208203
if len(options.MilestoneIDs) > 0 {
209204
query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
210205
}

modules/indexer/issues/indexer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func InitIssueIndexer(syncReindex bool) {
103103
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", setting.Indexer.IssueConnStr, err)
104104
}
105105
case "db":
106-
issueIndexer = db.NewIndexer()
106+
issueIndexer = db.GetIndexer()
107107
case "meilisearch":
108108
issueIndexer = meilisearch.NewIndexer(setting.Indexer.IssueConnStr, setting.Indexer.IssueConnAuth, setting.Indexer.IssueIndexerName)
109109
existed, err = issueIndexer.Init(ctx)
@@ -291,20 +291,22 @@ func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, err
291291
// 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.
292292
// Even worse, the external indexer like elastic search may not be available for a while,
293293
// and the user may not be able to list issues completely until it is available again.
294-
ix = db.NewIndexer()
294+
ix = db.GetIndexer()
295295
}
296296

297297
result, err := ix.Search(ctx, opts)
298298
if err != nil {
299299
return nil, 0, err
300300
}
301+
return SearchResultToIDSlice(result), result.Total, nil
302+
}
301303

304+
func SearchResultToIDSlice(result *internal.SearchResult) []int64 {
302305
ret := make([]int64, 0, len(result.Hits))
303306
for _, hit := range result.Hits {
304307
ret = append(ret, hit.ID)
305308
}
306-
307-
return ret, result.Total, nil
309+
return ret
308310
}
309311

310312
// CountIssues counts issues by options. It is a shortcut of SearchIssues(ctx, opts) but only returns the total count.

modules/indexer/issues/internal/model.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ type SearchOptions struct {
9494

9595
MilestoneIDs []int64 // milestones the issues have
9696

97-
IssueIDs []int64 // restrict search to these issues
98-
9997
ProjectID optional.Option[int64] // project the issues belong to
10098
ProjectColumnID optional.Option[int64] // project column the issues belong to
10199

0 commit comments

Comments
 (0)