@@ -40,16 +40,30 @@ import (
40
40
)
41
41
42
42
// 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 ) {
44
44
roleDescriptor := issues_model.RoleDescriptor {}
45
45
46
46
if hasOriginalAuthor {
47
47
return roleDescriptor , nil
48
48
}
49
49
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
+ }
53
67
}
54
68
55
69
// If the poster is the actual poster of the issue, enable Poster role.
@@ -576,6 +590,8 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
576
590
return
577
591
}
578
592
593
+ permCache := make (map [int64 ]access_model.Permission )
594
+
579
595
for _ , comment = range issue .Comments {
580
596
comment .Issue = issue
581
597
@@ -593,7 +609,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
593
609
continue
594
610
}
595
611
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 ())
597
613
if err != nil {
598
614
ctx .ServerError ("roleDescriptor" , err )
599
615
return
@@ -691,7 +707,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
691
707
continue
692
708
}
693
709
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 ())
695
711
if err != nil {
696
712
ctx .ServerError ("roleDescriptor" , err )
697
713
return
@@ -940,7 +956,7 @@ func prepareIssueViewContent(ctx *context.Context, issue *issues_model.Issue) {
940
956
ctx .ServerError ("RenderString" , err )
941
957
return
942
958
}
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 {
944
960
ctx .ServerError ("roleDescriptor" , err )
945
961
return
946
962
}
0 commit comments