diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-05-18 10:37:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-18 10:37:49 +0800 |
commit | c385dcc26b0da7fc1c245a1da316551cb6585ad3 (patch) | |
tree | 849ebbdf9ee3dbe2cf99842f26b1bf4ca7426172 /models/issue.go | |
parent | 96b412bb875f534e37b9af3d9e71842a2dadb6e0 (diff) | |
download | gitea-c385dcc26b0da7fc1c245a1da316551cb6585ad3.tar.gz gitea-c385dcc26b0da7fc1c245a1da316551cb6585ad3.zip |
Fix index produces problem when issues/pulls deleted (#6973)
* fix index produces problem when issues/pulls deleted
* fix tests
* fix tests
* fix tests
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/models/issue.go b/models/issue.go index f9394594be..999bd2f7a9 100644 --- a/models/issue.go +++ b/models/issue.go @@ -5,6 +5,7 @@ package models import ( + "errors" "fmt" "path" "regexp" @@ -1015,9 +1016,35 @@ type NewIssueOptions struct { IsPull bool } +// GetMaxIndexOfIssue returns the max index on issue +func GetMaxIndexOfIssue(repoID int64) (int64, error) { + return getMaxIndexOfIssue(x, repoID) +} + +func getMaxIndexOfIssue(e Engine, repoID int64) (int64, error) { + var ( + maxIndex int64 + has bool + err error + ) + + has, err = e.SQL("SELECT COALESCE((SELECT MAX(`index`) FROM issue WHERE repo_id = ?),0)", repoID).Get(&maxIndex) + if err != nil { + return 0, err + } else if !has { + return 0, errors.New("Retrieve Max index from issue failed") + } + return maxIndex, nil +} + func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) { opts.Issue.Title = strings.TrimSpace(opts.Issue.Title) - opts.Issue.Index = opts.Repo.NextIssueIndex() + + maxIndex, err := getMaxIndexOfIssue(e, opts.Issue.RepoID) + if err != nil { + return err + } + opts.Issue.Index = maxIndex + 1 if opts.Issue.MilestoneID > 0 { milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID) |