Skip to content

Commit 02999c9

Browse files
lunnytechknowlogick
authored andcommitted
improve branches list performance and fix protected branch icon when no-login (#7695)
1 parent a4b7a4f commit 02999c9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

routers/repo/branch.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func loadBranches(ctx *context.Context) []*Branch {
162162
return nil
163163
}
164164

165+
protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches()
166+
if err != nil {
167+
ctx.ServerError("GetProtectedBranches", err)
168+
return nil
169+
}
170+
165171
branches := make([]*Branch, len(rawBranches))
166172
for i := range rawBranches {
167173
commit, err := rawBranches[i].GetCommit()
@@ -170,11 +176,13 @@ func loadBranches(ctx *context.Context) []*Branch {
170176
return nil
171177
}
172178

179+
var isProtected bool
173180
branchName := rawBranches[i].Name
174-
isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User)
175-
if err != nil {
176-
ctx.ServerError("IsProtectedBranch", err)
177-
return nil
181+
for _, b := range protectedBranches {
182+
if b.BranchName == branchName {
183+
isProtected = true
184+
break
185+
}
178186
}
179187

180188
divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, branchName)

0 commit comments

Comments
 (0)