From 49f269374a464eebc032280ca7e217457ad44e7b Mon Sep 17 00:00:00 2001 From: "pdewey.com" Date: Sat, 7 Feb 2026 18:45:21 -0500 Subject: [PATCH] appview/pulls: fix search not updating count of pull requests searching for pull requests did not previously update open/merged/closed pull requests counts https://tangled.org/tangled.org/core/issues/400. Signed-off-by: pdewey.com --- appview/pulls/pulls.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index f037636b..6a55157f 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -553,6 +553,8 @@ func (s *Pulls) RepoPulls(w http.ResponseWriter, r *http.Request) { keyword := params.Get("q") + repoInfo := s.repoResolver.GetRepoInfo(r, user) + var pulls []*models.Pull searchOpts := models.PullSearchOptions{ Keyword: keyword, @@ -570,6 +572,36 @@ func (s *Pulls) RepoPulls(w http.ResponseWriter, r *http.Request) { totalPulls = int(res.Total) l.Debug("searched pulls with indexer", "count", len(res.Hits)) + // count matching pulls in the other states to display correct counts + for _, other := range []models.PullState{models.PullOpen, models.PullMerged, models.PullClosed} { + if other == state { + continue + } + countRes, err := s.indexer.Search(r.Context(), models.PullSearchOptions{ + Keyword: keyword, RepoAt: f.RepoAt().String(), State: other, + Page: pagination.Page{Limit: 1}, + }) + if err != nil { + continue + } + switch other { + case models.PullOpen: + repoInfo.Stats.PullCount.Open = int(countRes.Total) + case models.PullMerged: + repoInfo.Stats.PullCount.Merged = int(countRes.Total) + case models.PullClosed: + repoInfo.Stats.PullCount.Closed = int(countRes.Total) + } + } + switch state { + case models.PullOpen: + repoInfo.Stats.PullCount.Open = int(res.Total) + case models.PullMerged: + repoInfo.Stats.PullCount.Merged = int(res.Total) + case models.PullClosed: + repoInfo.Stats.PullCount.Closed = int(res.Total) + } + pulls, err = db.GetPulls( s.db, orm.FilterIn("id", res.Hits), @@ -668,7 +700,7 @@ func (s *Pulls) RepoPulls(w http.ResponseWriter, r *http.Request) { s.pages.RepoPulls(w, pages.RepoPullsParams{ LoggedInUser: s.oauth.GetMultiAccountUser(r), - RepoInfo: s.repoResolver.GetRepoInfo(r, user), + RepoInfo: repoInfo, Pulls: pulls, LabelDefs: defs, FilteringBy: state, -- 2.51.2