Skip to content

Commit b1a2f40

Browse files
committed
Follow yp05327's suggestion
1 parent c43f7ed commit b1a2f40

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

models/migrations/v1_22/v287.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2023 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
3+
34
package v1_22 //nolint
45

56
import (

models/project/issue.go

-24
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,6 @@ func (p *Project) NumOpenIssues(ctx context.Context) int {
7676
return int(c)
7777
}
7878

79-
// MoveIssuesOnProjectColumn moves or keeps issues in a column and sorts them inside that column
80-
func MoveIssuesOnProjectColumn(ctx context.Context, column *Column, sortedIssueIDs map[int64]int64) error {
81-
return db.WithTx(ctx, func(ctx context.Context) error {
82-
sess := db.GetEngine(ctx)
83-
issueIDs := util.ValuesOfMap(sortedIssueIDs)
84-
85-
count, err := sess.Table(new(ProjectIssue)).Where("project_id=?", column.ProjectID).In("issue_id", issueIDs).Count()
86-
if err != nil {
87-
return err
88-
}
89-
if int(count) != len(sortedIssueIDs) {
90-
return fmt.Errorf("all issues have to be added to a project first")
91-
}
92-
93-
for sorting, issueID := range sortedIssueIDs {
94-
_, err = sess.Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID)
95-
if err != nil {
96-
return err
97-
}
98-
}
99-
return nil
100-
})
101-
}
102-
10379
func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Column) error {
10480
if c.ProjectID != newColumn.ProjectID {
10581
return fmt.Errorf("columns have to be in the same project")

services/projects/issue.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,18 @@ func MoveIssuesOnProjectColumn(ctx context.Context, doer *user_model.User, colum
4444
return err
4545
}
4646

47+
issuesMap := make(map[int64]*issues_model.Issue, len(issues))
48+
for _, issue := range issues {
49+
issuesMap[issue.ID] = issue
50+
}
51+
4752
for sorting, issueID := range sortedIssueIDs {
4853
_, err = db.Exec(ctx, "UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID)
4954
if err != nil {
5055
return err
5156
}
5257

53-
var curIssue *issues_model.Issue
54-
for _, issue := range issues {
55-
if issue.ID == issueID {
56-
curIssue = issue
57-
break
58-
}
59-
}
58+
curIssue := issuesMap[issueID]
6059

6160
// add timeline to issue
6261
if _, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{

0 commit comments

Comments
 (0)