aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-08-13 15:06:18 +0200
committerGitHub <noreply@github.com>2021-08-13 21:06:18 +0800
commit3a6edd36851b266612f3d325bebc716fc60bfed5 (patch)
treefe985c6ff7a565ffafb01301176e4793c83a7561 /models/issue.go
parent6bf5afe5dec19a1c44494553e03e77625dd88eb8 (diff)
downloadgitea-3a6edd36851b266612f3d325bebc716fc60bfed5.tar.gz
gitea-3a6edd36851b266612f3d325bebc716fc60bfed5.zip
Update issue_index to finish migration (#16685)
* update issue_index to finish migration * One Func to RecalculateIssueIndexForRepo
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index 8b83612c2a..804d7dc101 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -982,6 +982,31 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
return opts.Issue.addCrossReferences(e, doer, false)
}
+// RecalculateIssueIndexForRepo create issue_index for repo if not exist and
+// update it based on highest index of existing issues assigned to a repo
+func RecalculateIssueIndexForRepo(repoID int64) error {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ if err := upsertResourceIndex(sess, "issue_index", repoID); err != nil {
+ return err
+ }
+
+ var max int64
+ if _, err := sess.Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max); err != nil {
+ return err
+ }
+
+ if _, err := sess.Exec("UPDATE `issue_index` SET max_index=? WHERE group_id=?", max, repoID); err != nil {
+ return err
+ }
+
+ return sess.Commit()
+}
+
// NewIssue creates new issue with labels for repository.
func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
idx, err := GetNextResourceIndex("issue_index", repo.ID)