@@ -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
@@ -345,29 +346,31 @@ func GetIssueBlocks(ctx *context.APIContext) {
345
346
return
346
347
}
347
348
348
- var lastRepoID int64
349
- var lastPerm access_model.Permission
350
-
351
349
var issues []* issues_model.Issue
350
+
351
+ repoPerms := make (map [int64 ]access_model.Permission )
352
+ repoPerms [ctx .Repo .Repository .ID ] = ctx .Repo .Permission
353
+
352
354
for i , depMeta := range deps {
353
355
if i < skip || i >= max {
354
356
continue
355
357
}
356
358
357
359
// Get the permissions for this repository
358
- perm := lastPerm
359
- if lastRepoID != depMeta .Repository .ID {
360
- if depMeta .Repository .ID == ctx .Repo .Repository .ID {
361
- perm = ctx .Repo .Permission
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
368
- }
360
+ // If the repo ID exists in the map, return the exist permissions
361
+ // else get the permission and add it to the map
362
+ var perm access_model.Permission
363
+ existPerm , ok := repoPerms [depMeta .RepoID ]
364
+ if ok {
365
+ perm = existPerm
366
+ } else {
367
+ var err error
368
+ perm , err = access_model .GetUserRepoPermission (ctx , & depMeta .Repository , ctx .Doer )
369
+ if err != nil {
370
+ ctx .ServerError ("GetUserRepoPermission" , err )
371
+ return
369
372
}
370
- lastRepoID = depMeta . Repository . ID
373
+ repoPerms [ depMeta . RepoID ] = perm
371
374
}
372
375
373
376
if ! perm .CanReadIssuesOrPulls (depMeta .Issue .IsPull ) {
0 commit comments