@@ -40,16 +40,30 @@ import (
4040)
4141
4242// roleDescriptor returns the role descriptor for a comment in/with the given repo, poster and issue
43- func roleDescriptor (ctx stdCtx.Context , repo * repo_model.Repository , poster * user_model.User , issue * issues_model.Issue , hasOriginalAuthor bool ) (issues_model.RoleDescriptor , error ) {
43+ 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 ) {
4444 roleDescriptor := issues_model.RoleDescriptor {}
4545
4646 if hasOriginalAuthor {
4747 return roleDescriptor , nil
4848 }
4949
50- perm , err := access_model .GetUserRepoPermission (ctx , repo , poster )
51- if err != nil {
52- return roleDescriptor , err
50+ var perm access_model.Permission
51+ var err error
52+ if permsCache != nil {
53+ var ok bool
54+ perm , ok = permsCache [poster .ID ]
55+ if ! ok {
56+ perm , err = access_model .GetUserRepoPermission (ctx , repo , poster )
57+ if err != nil {
58+ return roleDescriptor , err
59+ }
60+ }
61+ permsCache [poster .ID ] = perm
62+ } else {
63+ perm , err = access_model .GetUserRepoPermission (ctx , repo , poster )
64+ if err != nil {
65+ return roleDescriptor , err
66+ }
5367 }
5468
5569 // If the poster is the actual poster of the issue, enable Poster role.
@@ -576,6 +590,8 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
576590 return
577591 }
578592
593+ permCache := make (map [int64 ]access_model.Permission )
594+
579595 for _ , comment = range issue .Comments {
580596 comment .Issue = issue
581597
@@ -593,7 +609,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
593609 continue
594610 }
595611
596- comment .ShowRole , err = roleDescriptor (ctx , issue .Repo , comment .Poster , issue , comment .HasOriginalAuthor ())
612+ comment .ShowRole , err = roleDescriptor (ctx , issue .Repo , comment .Poster , permCache , issue , comment .HasOriginalAuthor ())
597613 if err != nil {
598614 ctx .ServerError ("roleDescriptor" , err )
599615 return
@@ -691,7 +707,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
691707 continue
692708 }
693709
694- c .ShowRole , err = roleDescriptor (ctx , issue .Repo , c .Poster , issue , c .HasOriginalAuthor ())
710+ c .ShowRole , err = roleDescriptor (ctx , issue .Repo , c .Poster , permCache , issue , c .HasOriginalAuthor ())
695711 if err != nil {
696712 ctx .ServerError ("roleDescriptor" , err )
697713 return
@@ -940,7 +956,7 @@ func prepareIssueViewContent(ctx *context.Context, issue *issues_model.Issue) {
940956 ctx .ServerError ("RenderString" , err )
941957 return
942958 }
943- if issue .ShowRole , err = roleDescriptor (ctx , issue .Repo , issue .Poster , issue , issue .HasOriginalAuthor ()); err != nil {
959+ if issue .ShowRole , err = roleDescriptor (ctx , issue .Repo , issue .Poster , nil , issue , issue .HasOriginalAuthor ()); err != nil {
944960 ctx .ServerError ("roleDescriptor" , err )
945961 return
946962 }
0 commit comments