Skip to content

Commit d43620e

Browse files
authored
Add is_archived option for issue indexer (#32735)
Try to fix #32697 Reason: `is_archived` is already defined in the query options, but it is not implemented in the indexer.
1 parent 39a0101 commit d43620e

File tree

9 files changed

+62
-11
lines changed

9 files changed

+62
-11
lines changed

modules/indexer/issues/bleve/bleve.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
const (
2424
issueIndexerAnalyzer = "issueIndexer"
2525
issueIndexerDocType = "issueIndexerDocType"
26-
issueIndexerLatestVersion = 4
26+
issueIndexerLatestVersion = 5
2727
)
2828

2929
const unicodeNormalizeName = "unicodeNormalize"
@@ -75,6 +75,7 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) {
7575

7676
docMapping.AddFieldMappingsAt("is_pull", boolFieldMapping)
7777
docMapping.AddFieldMappingsAt("is_closed", boolFieldMapping)
78+
docMapping.AddFieldMappingsAt("is_archived", boolFieldMapping)
7879
docMapping.AddFieldMappingsAt("label_ids", numberFieldMapping)
7980
docMapping.AddFieldMappingsAt("no_label", boolFieldMapping)
8081
docMapping.AddFieldMappingsAt("milestone_id", numberFieldMapping)
@@ -185,6 +186,9 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
185186
if options.IsClosed.Has() {
186187
queries = append(queries, inner_bleve.BoolFieldQuery(options.IsClosed.Value(), "is_closed"))
187188
}
189+
if options.IsArchived.Has() {
190+
queries = append(queries, inner_bleve.BoolFieldQuery(options.IsArchived.Value(), "is_archived"))
191+
}
188192

189193
if options.NoLabelOnly {
190194
queries = append(queries, inner_bleve.BoolFieldQuery(true, "no_label"))

modules/indexer/issues/db/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
7272
UpdatedAfterUnix: options.UpdatedAfterUnix.Value(),
7373
UpdatedBeforeUnix: options.UpdatedBeforeUnix.Value(),
7474
PriorityRepoID: 0,
75-
IsArchived: optional.None[bool](),
75+
IsArchived: options.IsArchived,
7676
Org: nil,
7777
Team: nil,
7878
User: nil,

modules/indexer/issues/dboptions.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111

1212
func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOptions {
1313
searchOpt := &SearchOptions{
14-
Keyword: keyword,
15-
RepoIDs: opts.RepoIDs,
16-
AllPublic: opts.AllPublic,
17-
IsPull: opts.IsPull,
18-
IsClosed: opts.IsClosed,
14+
Keyword: keyword,
15+
RepoIDs: opts.RepoIDs,
16+
AllPublic: opts.AllPublic,
17+
IsPull: opts.IsPull,
18+
IsClosed: opts.IsClosed,
19+
IsArchived: opts.IsArchived,
1920
}
2021

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

modules/indexer/issues/elasticsearch/elasticsearch.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
issueIndexerLatestVersion = 1
21+
issueIndexerLatestVersion = 2
2222
// multi-match-types, currently only 2 types are used
2323
// Reference: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-multi-match-query.html#multi-match-types
2424
esMultiMatchTypeBestFields = "best_fields"
@@ -58,6 +58,7 @@ const (
5858
5959
"is_pull": { "type": "boolean", "index": true },
6060
"is_closed": { "type": "boolean", "index": true },
61+
"is_archived": { "type": "boolean", "index": true },
6162
"label_ids": { "type": "integer", "index": true },
6263
"no_label": { "type": "boolean", "index": true },
6364
"milestone_id": { "type": "integer", "index": true },
@@ -168,6 +169,9 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
168169
if options.IsClosed.Has() {
169170
query.Must(elastic.NewTermQuery("is_closed", options.IsClosed.Value()))
170171
}
172+
if options.IsArchived.Has() {
173+
query.Must(elastic.NewTermQuery("is_archived", options.IsArchived.Value()))
174+
}
171175

172176
if options.NoLabelOnly {
173177
query.Must(elastic.NewTermQuery("no_label", true))

modules/indexer/issues/indexer_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestDBSearchIssues(t *testing.T) {
3737
t.Run("search issues by ID", searchIssueByID)
3838
t.Run("search issues is pr", searchIssueIsPull)
3939
t.Run("search issues is closed", searchIssueIsClosed)
40+
t.Run("search issues is archived", searchIssueIsArchived)
4041
t.Run("search issues by milestone", searchIssueByMilestoneID)
4142
t.Run("search issues by label", searchIssueByLabelID)
4243
t.Run("search issues by time", searchIssueByTime)
@@ -298,6 +299,33 @@ func searchIssueIsClosed(t *testing.T) {
298299
}
299300
}
300301

302+
func searchIssueIsArchived(t *testing.T) {
303+
tests := []struct {
304+
opts SearchOptions
305+
expectedIDs []int64
306+
}{
307+
{
308+
SearchOptions{
309+
IsArchived: optional.Some(false),
310+
},
311+
[]int64{22, 21, 17, 16, 15, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
312+
},
313+
{
314+
SearchOptions{
315+
IsArchived: optional.Some(true),
316+
},
317+
[]int64{14},
318+
},
319+
}
320+
for _, test := range tests {
321+
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
322+
if !assert.NoError(t, err) {
323+
return
324+
}
325+
assert.Equal(t, test.expectedIDs, issueIDs)
326+
}
327+
}
328+
301329
func searchIssueByMilestoneID(t *testing.T) {
302330
tests := []struct {
303331
opts SearchOptions

modules/indexer/issues/internal/model.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type IndexerData struct {
2525
// Fields used for filtering
2626
IsPull bool `json:"is_pull"`
2727
IsClosed bool `json:"is_closed"`
28+
IsArchived bool `json:"is_archived"`
2829
LabelIDs []int64 `json:"label_ids"`
2930
NoLabel bool `json:"no_label"` // True if LabelIDs is empty
3031
MilestoneID int64 `json:"milestone_id"`
@@ -81,8 +82,9 @@ type SearchOptions struct {
8182
RepoIDs []int64 // repository IDs which the issues belong to
8283
AllPublic bool // if include all public repositories
8384

84-
IsPull optional.Option[bool] // if the issues is a pull request
85-
IsClosed optional.Option[bool] // if the issues is closed
85+
IsPull optional.Option[bool] // if the issues is a pull request
86+
IsClosed optional.Option[bool] // if the issues is closed
87+
IsArchived optional.Option[bool] // if the repo is archived
8688

8789
IncludedLabelIDs []int64 // labels the issues have
8890
ExcludedLabelIDs []int64 // labels the issues don't have

modules/indexer/issues/meilisearch/meilisearch.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
issueIndexerLatestVersion = 3
21+
issueIndexerLatestVersion = 4
2222

2323
// TODO: make this configurable if necessary
2424
maxTotalHits = 10000
@@ -61,6 +61,7 @@ func NewIndexer(url, apiKey, indexerName string) *Indexer {
6161
"is_public",
6262
"is_pull",
6363
"is_closed",
64+
"is_archived",
6465
"label_ids",
6566
"no_label",
6667
"milestone_id",
@@ -145,6 +146,9 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
145146
if options.IsClosed.Has() {
146147
query.And(inner_meilisearch.NewFilterEq("is_closed", options.IsClosed.Value()))
147148
}
149+
if options.IsArchived.Has() {
150+
query.And(inner_meilisearch.NewFilterEq("is_archived", options.IsArchived.Value()))
151+
}
148152

149153
if options.NoLabelOnly {
150154
query.And(inner_meilisearch.NewFilterEq("no_label", true))

modules/indexer/issues/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
101101
Comments: comments,
102102
IsPull: issue.IsPull,
103103
IsClosed: issue.IsClosed,
104+
IsArchived: issue.Repo.IsArchived,
104105
LabelIDs: labels,
105106
NoLabel: len(labels) == 0,
106107
MilestoneID: issue.MilestoneID,

routers/web/repo/setting/setting.go

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/base"
2323
"code.gitea.io/gitea/modules/git"
2424
"code.gitea.io/gitea/modules/indexer/code"
25+
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
2526
"code.gitea.io/gitea/modules/indexer/stats"
2627
"code.gitea.io/gitea/modules/lfs"
2728
"code.gitea.io/gitea/modules/log"
@@ -905,6 +906,9 @@ func SettingsPost(ctx *context.Context) {
905906
log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err)
906907
}
907908

909+
// update issue indexer
910+
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
911+
908912
ctx.Flash.Success(ctx.Tr("repo.settings.archive.success"))
909913

910914
log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
@@ -929,6 +933,9 @@ func SettingsPost(ctx *context.Context) {
929933
}
930934
}
931935

936+
// update issue indexer
937+
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
938+
932939
ctx.Flash.Success(ctx.Tr("repo.settings.unarchive.success"))
933940

934941
log.Trace("Repository was un-archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)

0 commit comments

Comments
 (0)