gitea源码

issue_index.go 694B

123456789101112131415161718192021222324
  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. return db.WithTx(ctx, func(ctx context.Context) error {
  12. var maxIndex int64
  13. if _, err := db.GetEngine(ctx).Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&maxIndex); err != nil {
  14. return err
  15. }
  16. return db.SyncMaxResourceIndex(ctx, "issue_index", repoID, maxIndex)
  17. })
  18. }