@@ -102,23 +102,24 @@ func GetIssueDependencies(ctx *context.APIContext) {
102
102
return
103
103
}
104
104
105
- var lastRepoID int64
106
- var lastPerm access_model .Permission
105
+ repoPerms := make ( map [ int64 ]access_model. Permission )
106
+ repoPerms [ ctx . Repo . Repository . ID ] = ctx . Repo .Permission
107
107
for _ , blocker := range blockersInfo {
108
108
// Get the permissions for this repository
109
- perm := lastPerm
110
- if lastRepoID != blocker .Repository .ID {
111
- if blocker .Repository .ID == ctx .Repo .Repository .ID {
112
- perm = ctx .Repo .Permission
113
- } else {
114
- var err error
115
- perm , err = access_model .GetUserRepoPermission (ctx , & blocker .Repository , ctx .Doer )
116
- if err != nil {
117
- ctx .ServerError ("GetUserRepoPermission" , err )
118
- return
119
- }
109
+ // If the repo ID exists in the map, return the exist permissions
110
+ // else get the permission and add it to the map
111
+ var perm access_model.Permission
112
+ existPerm , ok := repoPerms [blocker .RepoID ]
113
+ if ok {
114
+ perm = existPerm
115
+ } else {
116
+ var err error
117
+ perm , err = access_model .GetUserRepoPermission (ctx , & blocker .Repository , ctx .Doer )
118
+ if err != nil {
119
+ ctx .ServerError ("GetUserRepoPermission" , err )
120
+ return
120
121
}
121
- lastRepoID = blocker . Repository . ID
122
+ repoPerms [ blocker . RepoID ] = perm
122
123
}
123
124
124
125
// check permission
@@ -341,29 +342,31 @@ func GetIssueBlocks(ctx *context.APIContext) {
341
342
return
342
343
}
343
344
344
- var lastRepoID int64
345
- var lastPerm access_model.Permission
346
-
347
345
var issues []* issues_model.Issue
346
+
347
+ repoPerms := make (map [int64 ]access_model.Permission )
348
+ repoPerms [ctx .Repo .Repository .ID ] = ctx .Repo .Permission
349
+
348
350
for i , depMeta := range deps {
349
351
if i < skip || i >= max {
350
352
continue
351
353
}
352
354
353
355
// Get the permissions for this repository
354
- perm := lastPerm
355
- if lastRepoID != depMeta .Repository .ID {
356
- if depMeta .Repository .ID == ctx .Repo .Repository .ID {
357
- perm = ctx .Repo .Permission
358
- } else {
359
- var err error
360
- perm , err = access_model .GetUserRepoPermission (ctx , & depMeta .Repository , ctx .Doer )
361
- if err != nil {
362
- ctx .ServerError ("GetUserRepoPermission" , err )
363
- return
364
- }
356
+ // If the repo ID exists in the map, return the exist permissions
357
+ // else get the permission and add it to the map
358
+ var perm access_model.Permission
359
+ existPerm , ok := repoPerms [depMeta .RepoID ]
360
+ if ok {
361
+ perm = existPerm
362
+ } else {
363
+ var err error
364
+ perm , err = access_model .GetUserRepoPermission (ctx , & depMeta .Repository , ctx .Doer )
365
+ if err != nil {
366
+ ctx .ServerError ("GetUserRepoPermission" , err )
367
+ return
365
368
}
366
- lastRepoID = depMeta . Repository . ID
369
+ repoPerms [ depMeta . RepoID ] = perm
367
370
}
368
371
369
372
if ! perm .CanReadIssuesOrPulls (depMeta .Issue .IsPull ) {
0 commit comments