]> source.dussan.org Git - gitea.git/commitdiff
improve branches list performance and fix protected branch icon when no-login (#7695... 7716/head
authorLunny Xiao <xiaolunwen@gmail.com>
Thu, 1 Aug 2019 15:40:00 +0000 (23:40 +0800)
committertechknowlogick <techknowlogick@gitea.io>
Thu, 1 Aug 2019 15:40:00 +0000 (11:40 -0400)
routers/repo/branch.go

index 3bd4a75bfb3c040f38535324e0b8560e41e05250..5d78518491dfa2207679ad722d7e358f75bbcf3b 100644 (file)
@@ -162,6 +162,12 @@ func loadBranches(ctx *context.Context) []*Branch {
                return nil
        }
 
+       protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches()
+       if err != nil {
+               ctx.ServerError("GetProtectedBranches", err)
+               return nil
+       }
+
        branches := make([]*Branch, len(rawBranches))
        for i := range rawBranches {
                commit, err := rawBranches[i].GetCommit()
@@ -170,11 +176,13 @@ func loadBranches(ctx *context.Context) []*Branch {
                        return nil
                }
 
+               var isProtected bool
                branchName := rawBranches[i].Name
-               isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User)
-               if err != nil {
-                       ctx.ServerError("IsProtectedBranch", err)
-                       return nil
+               for _, b := range protectedBranches {
+                       if b.BranchName == branchName {
+                               isProtected = true
+                               break
+                       }
                }
 
                divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, branchName)