aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2025-01-09 22:00:06 -0800
committerGitHub <noreply@github.com>2025-01-10 06:00:06 +0000
commitd3083d21981f9445cf7570956a1fdedfc8578b56 (patch)
tree462ab0690b285144b5e53ffb74aaa3434d80eadb /routers/web/repo
parente5f3c16587483daa18fa1db8bbc111452d9b864a (diff)
downloadgitea-d3083d21981f9445cf7570956a1fdedfc8578b56.tar.gz
gitea-d3083d21981f9445cf7570956a1fdedfc8578b56.zip
Some small refactors (#33144)
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/issue_view.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go
index 61e75e211b..aa49d2e1e8 100644
--- a/routers/web/repo/issue_view.go
+++ b/routers/web/repo/issue_view.go
@@ -40,16 +40,30 @@ import (
)
// roleDescriptor returns the role descriptor for a comment in/with the given repo, poster and issue
-func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
+func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, permsCache map[int64]access_model.Permission, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
roleDescriptor := issues_model.RoleDescriptor{}
if hasOriginalAuthor {
return roleDescriptor, nil
}
- perm, err := access_model.GetUserRepoPermission(ctx, repo, poster)
- if err != nil {
- return roleDescriptor, err
+ var perm access_model.Permission
+ var err error
+ if permsCache != nil {
+ var ok bool
+ perm, ok = permsCache[poster.ID]
+ if !ok {
+ perm, err = access_model.GetUserRepoPermission(ctx, repo, poster)
+ if err != nil {
+ return roleDescriptor, err
+ }
+ }
+ permsCache[poster.ID] = perm
+ } else {
+ perm, err = access_model.GetUserRepoPermission(ctx, repo, poster)
+ if err != nil {
+ return roleDescriptor, err
+ }
}
// If the poster is the actual poster of the issue, enable Poster role.
@@ -576,6 +590,8 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
return
}
+ permCache := make(map[int64]access_model.Permission)
+
for _, comment = range issue.Comments {
comment.Issue = issue
@@ -593,7 +609,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
continue
}
- comment.ShowRole, err = roleDescriptor(ctx, issue.Repo, comment.Poster, issue, comment.HasOriginalAuthor())
+ comment.ShowRole, err = roleDescriptor(ctx, issue.Repo, comment.Poster, permCache, issue, comment.HasOriginalAuthor())
if err != nil {
ctx.ServerError("roleDescriptor", err)
return
@@ -691,7 +707,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
continue
}
- c.ShowRole, err = roleDescriptor(ctx, issue.Repo, c.Poster, issue, c.HasOriginalAuthor())
+ c.ShowRole, err = roleDescriptor(ctx, issue.Repo, c.Poster, permCache, issue, c.HasOriginalAuthor())
if err != nil {
ctx.ServerError("roleDescriptor", err)
return
@@ -940,7 +956,7 @@ func prepareIssueViewContent(ctx *context.Context, issue *issues_model.Issue) {
ctx.ServerError("RenderString", err)
return
}
- if issue.ShowRole, err = roleDescriptor(ctx, issue.Repo, issue.Poster, issue, issue.HasOriginalAuthor()); err != nil {
+ if issue.ShowRole, err = roleDescriptor(ctx, issue.Repo, issue.Poster, nil, issue, issue.HasOriginalAuthor()); err != nil {
ctx.ServerError("roleDescriptor", err)
return
}