Monorepo for Tangled tangled.org

appview/issues: fix search not updating count of open/closed issues #1054

merged opened by pdewey.com targeting master from pdewey.com/tangled-core: push-mozonwyomvmy

Updates issue open/closed counts on in searches #400

Pull requests have the same issue, but they are not addressed in this PR.

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hm5f3dnm6jdhrc55qp2npdja/sh.tangled.repo.pull/3mecqnrub5b22
+18 -1
Diff #0
+18 -1
appview/issues/issues.go
··· 822 822 823 823 keyword := params.Get("q") 824 824 825 + repoInfo := rp.repoResolver.GetRepoInfo(r, user) 826 + 825 827 var issues []models.Issue 826 828 searchOpts := models.IssueSearchOptions{ 827 829 Keyword: keyword, ··· 838 840 l.Debug("searched issues with indexer", "count", len(res.Hits)) 839 841 totalIssues = int(res.Total) 840 842 843 + // count matching issues in the opposite state to display correct counts 844 + countRes, err := rp.indexer.Search(r.Context(), models.IssueSearchOptions{ 845 + Keyword: keyword, RepoAt: f.RepoAt().String(), IsOpen: !isOpen, 846 + Page: pagination.Page{Limit: 1}, 847 + }) 848 + if err == nil { 849 + if isOpen { 850 + repoInfo.Stats.IssueCount.Open = int(res.Total) 851 + repoInfo.Stats.IssueCount.Closed = int(countRes.Total) 852 + } else { 853 + repoInfo.Stats.IssueCount.Closed = int(res.Total) 854 + repoInfo.Stats.IssueCount.Open = int(countRes.Total) 855 + } 856 + } 857 + 841 858 issues, err = db.GetIssues( 842 859 rp.db, 843 860 orm.FilterIn("id", res.Hits), ··· 884 901 885 902 rp.pages.RepoIssues(w, pages.RepoIssuesParams{ 886 903 LoggedInUser: rp.oauth.GetMultiAccountUser(r), 887 - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 904 + RepoInfo: repoInfo, 888 905 Issues: issues, 889 906 IssueCount: totalIssues, 890 907 LabelDefs: defs,

History

1 round 3 comments
sign up or login to add to the discussion
pdewey.com submitted #0
1 commit
expand
appview/issues: fix search not updating count of open/closed issues
expand 3 comments

lovely, thank you! will give this a go locally, code itself looks good to me. the only caveat i can think of is that this will also show the filtered count in the repository tabs. we have a tab for [123] issues which is the count of all open issues on the repo, but upon performing a search, the tab will have [10] issues, which could be a bit confusing, but not a deal breaker IMO!

Ah, I missed that. I think that could be avoided by adding a couple of new fields (or a struct) for open/closed count to RepoIssuesParams, and using those in the templates instead of the RepoInfo counts.

tested locally and this works like charm! would love to see this for the pulls page too ;)

thanks for the contribution!

pull request successfully merged