code.gitea.io/gitea@v1.21.7/models/issues/issue_index.go (about)

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