You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_index.go 773B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package issues
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  7. )
  8. // RecalculateIssueIndexForRepo create issue_index for repo if not exist and
  9. // update it based on highest index of existing issues assigned to a repo
  10. func RecalculateIssueIndexForRepo(ctx context.Context, repoID int64) error {
  11. ctx, committer, err := db.TxContext(ctx)
  12. if err != nil {
  13. return err
  14. }
  15. defer committer.Close()
  16. var max int64
  17. if _, err = db.GetEngine(ctx).Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max); err != nil {
  18. return err
  19. }
  20. if err = db.SyncMaxResourceIndex(ctx, "issue_index", repoID, max); err != nil {
  21. return err
  22. }
  23. return committer.Commit()
  24. }