Skip to content

Commit 1bf5734

Browse files
committed
Fix conflicting
1 parent cc22c5f commit 1bf5734

File tree

10 files changed

+50
-69
lines changed

10 files changed

+50
-69
lines changed

models/issues/issue.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ type Issue struct {
105105
PosterID int64 `xorm:"INDEX"`
106106
Poster *user_model.User `xorm:"-"`
107107
OriginalAuthor string
108-
OriginalAuthorID int64 `xorm:"index"`
109-
Title string `xorm:"name"`
110-
Content string `xorm:"LONGTEXT"`
111-
RenderedContent template.HTML `xorm:"-"`
112-
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
113-
Labels []*Label `xorm:"-"`
114-
MilestoneID int64 `xorm:"INDEX"`
115-
Milestone *Milestone `xorm:"-"`
116-
Project *project_model.Project `xorm:"-"`
108+
OriginalAuthorID int64 `xorm:"index"`
109+
Title string `xorm:"name"`
110+
Content string `xorm:"LONGTEXT"`
111+
RenderedContent template.HTML `xorm:"-"`
112+
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
113+
Labels []*Label `xorm:"-"`
114+
MilestoneID int64 `xorm:"INDEX"`
115+
Milestone *Milestone `xorm:"-"`
116+
Projects []*project_model.Project `xorm:"-"`
117117
Priority int
118118
AssigneeID int64 `xorm:"-"`
119119
Assignee *user_model.User `xorm:"-"`

models/issues/issue_project.go

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func LoadIssuesFromColumnList(ctx context.Context, bs project_model.ColumnList)
8787
// If newProjectID is 0, the issue is removed from the project
8888
func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64, action string) error {
8989
return db.WithTx(ctx, func(ctx context.Context) error {
90-
oldProjectIDs := issue.projectIDs(ctx)
90+
var oldProjectIDs []int64
9191
var err error
9292
if err := issue.LoadRepo(ctx); err != nil {
9393
return err
@@ -111,65 +111,53 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
111111
}
112112
}
113113

114-
if action == "null" {
115-
if newProjectID == 0 {
116-
action = "clear"
117-
} else {
118-
action = "attach"
119-
count, err := db.GetEngine(ctx).Table("project_issue").Where("issue_id=? AND project_id=?", issue.ID, newProjectID).Count()
120-
if err != nil {
121-
return err
122-
}
123-
if count > 0 {
124-
action = "detach"
125-
}
126-
}
127-
}
128-
129-
if action == "attach" {
114+
if action == "attach" || (action == "null" && newProjectID > 0) {
130115
if newProjectID == 0 {
131116
return nil
132117
}
133118
if newColumnID == 0 {
134119
panic("newColumnID must not be zero") // shouldn't happen
135120
}
136121
res := struct {
137-
MaxSorting int64
138122
IssueCount int64
139123
}{}
140-
if _, err := db.GetEngine(ctx).Select("max(sorting) as max_sorting, count(*) as issue_count").Table("project_issue").
124+
if _, err := db.GetEngine(ctx).Select("count(*) as issue_count").Table("project_issue").
141125
Where("project_id=?", newProjectID).
142126
And("project_board_id=?", newColumnID).
143127
Get(&res); err != nil {
144128
return err
145129
}
146-
newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
147-
err = db.Insert(ctx, &project_model.ProjectIssue{
148-
IssueID: issue.ID,
149-
ProjectID: newProjectID,
150-
ProjectColumnID: newColumnID,
151-
Sorting: newSorting,
152-
})
153-
oldProjectIDs = append(oldProjectIDs, 0)
130+
if res.IssueCount == 0 {
131+
err = db.Insert(ctx, &project_model.ProjectIssue{
132+
IssueID: issue.ID,
133+
ProjectID: newProjectID,
134+
ProjectColumnID: newColumnID,
135+
})
136+
oldProjectIDs = []int64{0}
137+
} else {
138+
_, err = db.GetEngine(ctx).Where("issue_id=? AND project_id=?", issue.ID, newProjectID).Delete(&project_model.ProjectIssue{})
139+
oldProjectIDs = []int64{newProjectID}
140+
newProjectID = 0
141+
}
154142
} else if action == "detach" {
155143
_, err = db.GetEngine(ctx).Where("issue_id=? AND project_id=?", issue.ID, newProjectID).Delete(&project_model.ProjectIssue{})
156144
oldProjectIDs = append(oldProjectIDs, newProjectID)
157145
newProjectID = 0
158-
} else if action == "clear" {
146+
} else if action == "clear" || (action == "null" && newProjectID == 0) {
159147
if err = db.GetEngine(ctx).Table("project_issue").Select("project_id").Where("issue_id=?", issue.ID).Find(&oldProjectIDs); err != nil {
160148
return err
161149
}
162150
_, err = db.GetEngine(ctx).Where("issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{})
163151
newProjectID = 0
164152
}
165153

166-
for i := range oldProjectIDs {
154+
for _, oldProjectID := range oldProjectIDs {
167155
if _, err := CreateComment(ctx, &CreateCommentOptions{
168156
Type: CommentTypeProject,
169157
Doer: doer,
170158
Repo: issue.Repo,
171159
Issue: issue,
172-
OldProjectID: oldProjectIDs[i],
160+
OldProjectID: oldProjectID,
173161
ProjectID: newProjectID,
174162
}); err != nil {
175163
return err

modules/indexer/issues/bleve/bleve.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
222222
queries = append(queries, bleve.NewDisjunctionQuery(milestoneQueries...))
223223
}
224224

225-
if options.ProjectID.Has() {
226-
if v := options.ProjectID.Value(); v != 0 {
227-
queries = append(queries, inner_bleve.NumericEqualityQuery(v, "project_ids"))
228-
} else {
229-
queries = append(queries, inner_bleve.BoolFieldQuery(true, "no_project"))
225+
if len(options.ProjectIDs) > 0 {
226+
var projectQueries []query.Query
227+
for _, projectID := range options.ProjectIDs {
228+
projectQueries = append(projectQueries, inner_bleve.NumericEqualityQuery(projectID, "project_ids"))
230229
}
230+
queries = append(queries, bleve.NewDisjunctionQuery(projectQueries...))
231231
}
232232
if options.ProjectColumnID.Has() {
233233
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))

modules/indexer/issues/db/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
6060
ReviewRequestedID: convertID(options.ReviewRequestedID),
6161
ReviewedID: convertID(options.ReviewedID),
6262
SubscriberID: convertID(options.SubscriberID),
63-
ProjectID: convertID(options.ProjectID),
63+
ProjectID: convertID(options.ProjectIDs),
6464
ProjectColumnID: convertID(options.ProjectColumnID),
6565
IsClosed: options.IsClosed,
6666
IsPull: options.IsPull,

modules/indexer/issues/dboptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
4949
return nil
5050
}
5151

52-
searchOpt.ProjectID = convertID(opts.ProjectID)
52+
searchOpt.ProjectIDs = convertID(opts.ProjectID)
5353
searchOpt.ProjectColumnID = convertID(opts.ProjectColumnID)
5454
searchOpt.PosterID = convertID(opts.PosterID)
5555
searchOpt.AssigneeID = convertID(opts.AssigneeID)

modules/indexer/issues/elasticsearch/elasticsearch.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
195195
query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
196196
}
197197

198-
if options.ProjectID.Has() {
199-
if v := options.ProjectID.Value(); v != 0 {
200-
query.Must(elastic.NewTermQuery("project_ids", v))
201-
} else {
202-
query.Must(elastic.NewTermQuery("no_project", true))
203-
}
198+
if len(options.ProjectIDs) > 0 {
199+
query.Must(elastic.NewTermsQuery("project_ids", toAnySlice(options.ProjectIDs)...))
204200
}
205201
if options.ProjectColumnID.Has() {
206202
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))

modules/indexer/issues/internal/model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ type IndexerData struct {
2626
LabelIDs []int64 `json:"label_ids"`
2727
NoLabel bool `json:"no_label"` // True if LabelIDs is empty
2828
MilestoneID int64 `json:"milestone_id"`
29-
ProjectIDs int64 `json:"project_ids"`
29+
ProjectIDs []int64 `json:"project_ids"`
30+
NoProject bool `json:"no_project"` // True if ProjectIDs is empty
3031
ProjectColumnID int64 `json:"project_board_id"` // the key should be kept as project_board_id to keep compatible
3132
PosterID int64 `json:"poster_id"`
3233
AssigneeID int64 `json:"assignee_id"`
@@ -89,7 +90,7 @@ type SearchOptions struct {
8990

9091
MilestoneIDs []int64 // milestones the issues have
9192

92-
ProjectID optional.Option[int64] // project the issues belong to
93+
ProjectIDs []int64 // project the issues belong to
9394
ProjectColumnID optional.Option[int64] // project column the issues belong to
9495

9596
PosterID optional.Option[int64] // poster of the issues

modules/indexer/issues/internal/tests/tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ var cases = []*testIndexerCase{
307307
Paginator: &db.ListOptions{
308308
PageSize: 5,
309309
},
310-
ProjectID: optional.Some(int64(1)),
310+
ProjectIDs: optional.Some(int64(1)),
311311
},
312312
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
313313
assert.Equal(t, 5, len(result.Hits))
@@ -325,7 +325,7 @@ var cases = []*testIndexerCase{
325325
Paginator: &db.ListOptions{
326326
PageSize: 5,
327327
},
328-
ProjectID: optional.Some(int64(0)),
328+
ProjectIDs: optional.Some(int64(0)),
329329
},
330330
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
331331
assert.Equal(t, 5, len(result.Hits))

modules/indexer/issues/meilisearch/meilisearch.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
172172
query.And(inner_meilisearch.NewFilterIn("milestone_id", options.MilestoneIDs...))
173173
}
174174

175-
if options.ProjectID.Has() {
176-
if v := options.ProjectID.Value(); v != 0 {
177-
query.And(inner_meilisearch.NewFilterEq("project_ids", v))
178-
} else {
179-
query.And(inner_meilisearch.NewFilterEq("no_label", true))
180-
}
175+
if len(options.ProjectIDs) > 0 {
176+
query.And(inner_meilisearch.NewFilterIn("project_ids", options.ProjectIDs...))
181177
}
182178
if options.ProjectColumnID.Has() {
183179
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectColumnID.Value()))

routers/web/repo/issue.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ func SearchIssues(ctx *context.Context) {
26702670
IsClosed: isClosed,
26712671
IncludedAnyLabelIDs: includedAnyLabels,
26722672
MilestoneIDs: includedMilestones,
2673-
ProjectID: projectID,
2673+
ProjectIDs: projectID,
26742674
SortBy: issue_indexer.SortByCreatedDesc,
26752675
}
26762676

@@ -2833,12 +2833,12 @@ func ListIssues(ctx *context.Context) {
28332833
Page: ctx.FormInt("page"),
28342834
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
28352835
},
2836-
Keyword: keyword,
2837-
RepoIDs: []int64{ctx.Repo.Repository.ID},
2838-
IsPull: isPull,
2839-
IsClosed: isClosed,
2840-
ProjectID: projectID,
2841-
SortBy: issue_indexer.SortByCreatedDesc,
2836+
Keyword: keyword,
2837+
RepoIDs: []int64{ctx.Repo.Repository.ID},
2838+
IsPull: isPull,
2839+
IsClosed: isClosed,
2840+
ProjectIDs: projectID,
2841+
SortBy: issue_indexer.SortByCreatedDesc,
28422842
}
28432843
if since != 0 {
28442844
searchOpt.UpdatedAfterUnix = optional.Some(since)

0 commit comments

Comments
 (0)