Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

appview: update tab counts to reflect search filters

When searching issues or pulls with filters, the open/closed tab counts
were showing unfiltered repo totals. Run per-state count queries when a
search is active and update RepoInfo.Stats before rendering.

Based on a fix by Patrick Dewey (pdewey.com) for issue #400.

Signed-off-by: Thomas Karpiniec <tkarpiniec@icloud.com>

authored by octet-stream.net and committed by tangled.org 2dc39aff b162fea0

+35 -1
+15 -1
appview/issues/issues.go
··· 892 892 totalIssues = f.RepoStats.IssueCount.Closed 893 893 } 894 894 895 + repoInfo := rp.repoResolver.GetRepoInfo(r, user) 896 + 895 897 var issues []models.Issue 896 898 897 899 if searchOpts.HasSearchFilters() { ··· 904 902 } 905 903 l.Debug("searched issues with indexer", "count", len(res.Hits)) 906 904 totalIssues = int(res.Total) 905 + 906 + // update tab counts to reflect filtered results 907 + countOpts := searchOpts 908 + countOpts.Page = pagination.Page{Limit: 1} 909 + countOpts.IsOpen = ptrBool(true) 910 + if openRes, err := rp.indexer.Search(r.Context(), countOpts); err == nil { 911 + repoInfo.Stats.IssueCount.Open = int(openRes.Total) 912 + } 913 + countOpts.IsOpen = ptrBool(false) 914 + if closedRes, err := rp.indexer.Search(r.Context(), countOpts); err == nil { 915 + repoInfo.Stats.IssueCount.Closed = int(closedRes.Total) 916 + } 907 917 908 918 if len(res.Hits) > 0 { 909 919 issues, err = db.GetIssues( ··· 978 964 979 965 rp.pages.RepoIssues(w, pages.RepoIssuesParams{ 980 966 LoggedInUser: rp.oauth.GetMultiAccountUser(r), 981 - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 967 + RepoInfo: repoInfo, 982 968 Issues: issues, 983 969 IssueCount: totalIssues, 984 970 LabelDefs: defs,
+20
appview/pulls/pulls.go
··· 643 643 totalPulls = int(res.Total) 644 644 l.Debug("searched pulls with indexer", "count", len(res.Hits)) 645 645 646 + // update tab counts to reflect filtered results 647 + countOpts := searchOpts 648 + countOpts.Page = pagination.Page{Limit: 1} 649 + for _, ps := range []models.PullState{models.PullOpen, models.PullMerged, models.PullClosed} { 650 + ps := ps 651 + countOpts.State = &ps 652 + countRes, err := s.indexer.Search(r.Context(), countOpts) 653 + if err != nil { 654 + continue 655 + } 656 + switch ps { 657 + case models.PullOpen: 658 + repoInfo.Stats.PullCount.Open = int(countRes.Total) 659 + case models.PullMerged: 660 + repoInfo.Stats.PullCount.Merged = int(countRes.Total) 661 + case models.PullClosed: 662 + repoInfo.Stats.PullCount.Closed = int(countRes.Total) 663 + } 664 + } 665 + 646 666 if len(res.Hits) > 0 { 647 667 pulls, err = db.GetPulls( 648 668 s.db,