Skip to content

Commit 3a6edd3

Browse files
authored
Update issue_index to finish migration (#16685)
* update issue_index to finish migration * One Func to RecalculateIssueIndexForRepo
1 parent 6bf5afe commit 3a6edd3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

models/issue.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,31 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
982982
return opts.Issue.addCrossReferences(e, doer, false)
983983
}
984984

985+
// RecalculateIssueIndexForRepo create issue_index for repo if not exist and
986+
// update it based on highest index of existing issues assigned to a repo
987+
func RecalculateIssueIndexForRepo(repoID int64) error {
988+
sess := x.NewSession()
989+
defer sess.Close()
990+
if err := sess.Begin(); err != nil {
991+
return err
992+
}
993+
994+
if err := upsertResourceIndex(sess, "issue_index", repoID); err != nil {
995+
return err
996+
}
997+
998+
var max int64
999+
if _, err := sess.Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max); err != nil {
1000+
return err
1001+
}
1002+
1003+
if _, err := sess.Exec("UPDATE `issue_index` SET max_index=? WHERE group_id=?", max, repoID); err != nil {
1004+
return err
1005+
}
1006+
1007+
return sess.Commit()
1008+
}
1009+
9851010
// NewIssue creates new issue with labels for repository.
9861011
func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
9871012
idx, err := GetNextResourceIndex("issue_index", repo.ID)

modules/migrations/gitea_uploader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,11 @@ func (g *GiteaLocalUploader) Finish() error {
871871
return ErrRepoNotCreated
872872
}
873873

874+
// update issue_index
875+
if err := models.RecalculateIssueIndexForRepo(g.repo.ID); err != nil {
876+
return err
877+
}
878+
874879
g.repo.Status = models.RepositoryReady
875880
return models.UpdateRepositoryCols(g.repo, "status")
876881
}

0 commit comments

Comments
 (0)