diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-08-01 22:50:06 +0800 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-08-01 10:50:06 -0400 |
commit | 02999c9a44cc0d681a46ef947930fbc0998e440c (patch) | |
tree | d0934dff07baf92cf8b3119bffa9526ef8e006ed | |
parent | a4b7a4f2f8acc56a82b29b4fbad7627d71d3d4db (diff) | |
download | gitea-02999c9a44cc0d681a46ef947930fbc0998e440c.tar.gz gitea-02999c9a44cc0d681a46ef947930fbc0998e440c.zip |
improve branches list performance and fix protected branch icon when no-login (#7695)
-rw-r--r-- | routers/repo/branch.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 3bd4a75bfb..5d78518491 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -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) |