more context for models (#19511)

make more usage of context, to have more db transaction in one session

(make diff of  #9307 smaller)
This commit is contained in:
6543 2022-04-28 13:48:48 +02:00 committed by GitHub
parent 332b2ecd21
commit 06e4687cec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 275 additions and 245 deletions

View file

@ -6,6 +6,7 @@
package repo
import (
stdCtx "context"
"errors"
"net/http"
@ -183,7 +184,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
var apiComments []*api.TimelineComment
for _, comment := range comments {
if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx.Doer, comment, issue.RepoID) {
if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx, ctx.Doer, comment, issue.RepoID) {
comment.Issue = issue
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.Doer))
}
@ -193,16 +194,16 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, &apiComments)
}
func isXRefCommentAccessible(user *user_model.User, c *models.Comment, issueRepoID int64) bool {
func isXRefCommentAccessible(ctx stdCtx.Context, user *user_model.User, c *models.Comment, issueRepoID int64) bool {
// Remove comments that the user has no permissions to see
if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issueRepoID && c.RefRepoID != 0 {
var err error
// Set RefRepo for description in template
c.RefRepo, err = repo_model.GetRepositoryByID(c.RefRepoID)
c.RefRepo, err = repo_model.GetRepositoryByIDCtx(ctx, c.RefRepoID)
if err != nil {
return false
}
perm, err := models.GetUserRepoPermission(c.RefRepo, user)
perm, err := models.GetUserRepoPermission(ctx, c.RefRepo, user)
if err != nil {
return false
}