@@ -49,6 +49,16 @@ func (h *Handlers) branchesList(w http.ResponseWriter, r *http.Request) { |
| 49 | 49 | rules, _ := h.rq.ListBranchProtectionRules(r.Context(), h.d.Pool, row.ID) |
| 50 | 50 | |
| 51 | 51 | defaultBranch := row.DefaultBranch |
| 52 | + // Resolve the default's OID once so the cached AheadBehind key is |
| 53 | + // OID-based (immutable across same-OID pushes; cache stays hot |
| 54 | + // when other branches advance). |
| 55 | + defaultOID := "" |
| 56 | + for _, b := range refs.Branches { |
| 57 | + if b.Name == defaultBranch { |
| 58 | + defaultOID = b.OID |
| 59 | + break |
| 60 | + } |
| 61 | + } |
| 52 | 62 | rows := make([]branchRow, 0, len(refs.Branches)) |
| 53 | 63 | now := time.Now() |
| 54 | 64 | for _, b := range refs.Branches { |
@@ -62,10 +72,12 @@ func (h *Handlers) branchesList(w http.ResponseWriter, r *http.Request) { |
| 62 | 72 | br.LastWhen = hc.AuthorWhen |
| 63 | 73 | br.Stale = now.Sub(hc.AuthorWhen) > 90*24*time.Hour |
| 64 | 74 | } |
| 65 | | - if b.Name != defaultBranch { |
| 66 | | - ahead, behind, _ := repogit.AheadBehind(r.Context(), gitDir, defaultBranch, b.Name) |
| 67 | | - br.Ahead = ahead |
| 68 | | - br.Behind = behind |
| 75 | + if b.Name != defaultBranch && defaultOID != "" { |
| 76 | + res, _ := repogit.AheadBehindCached(r.Context(), gitDir, repogit.AheadBehindKey{ |
| 77 | + RepoID: row.ID, BaseOID: defaultOID, HeadOID: b.OID, |
| 78 | + }) |
| 79 | + br.Ahead = res.Ahead |
| 80 | + br.Behind = res.Behind |
| 69 | 81 | } |
| 70 | 82 | br.IsDefault = b.Name == defaultBranch |
| 71 | 83 | br.Protected = isBranchProtected(rules, b.Name) |