Monorepo for Tangled tangled.org

appview/pulls: fix search not updating count of pull requests #1062

merged opened by pdewey.com targeting master

Updates pull request open/merged/closed counts on in searches (follow up to #1054)

I'm submitting this via a patch (which I've never done before) so please let me know if there are any issues.

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hm5f3dnm6jdhrc55qp2npdja/sh.tangled.repo.pull/3mehw75hvuz22
+33 -1
Diff #0
+33 -1
appview/pulls/pulls.go
··· 553 554 keyword := params.Get("q") 555 556 var pulls []*models.Pull 557 searchOpts := models.PullSearchOptions{ 558 Keyword: keyword, ··· 570 totalPulls = int(res.Total) 571 l.Debug("searched pulls with indexer", "count", len(res.Hits)) 572 573 pulls, err = db.GetPulls( 574 s.db, 575 orm.FilterIn("id", res.Hits), ··· 668 669 s.pages.RepoPulls(w, pages.RepoPullsParams{ 670 LoggedInUser: s.oauth.GetMultiAccountUser(r), 671 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 672 Pulls: pulls, 673 LabelDefs: defs, 674 FilteringBy: state,
··· 553 554 keyword := params.Get("q") 555 556 + repoInfo := s.repoResolver.GetRepoInfo(r, user) 557 + 558 var pulls []*models.Pull 559 searchOpts := models.PullSearchOptions{ 560 Keyword: keyword, ··· 572 totalPulls = int(res.Total) 573 l.Debug("searched pulls with indexer", "count", len(res.Hits)) 574 575 + // count matching pulls in the other states to display correct counts 576 + for _, other := range []models.PullState{models.PullOpen, models.PullMerged, models.PullClosed} { 577 + if other == state { 578 + continue 579 + } 580 + countRes, err := s.indexer.Search(r.Context(), models.PullSearchOptions{ 581 + Keyword: keyword, RepoAt: f.RepoAt().String(), State: other, 582 + Page: pagination.Page{Limit: 1}, 583 + }) 584 + if err != nil { 585 + continue 586 + } 587 + switch other { 588 + case models.PullOpen: 589 + repoInfo.Stats.PullCount.Open = int(countRes.Total) 590 + case models.PullMerged: 591 + repoInfo.Stats.PullCount.Merged = int(countRes.Total) 592 + case models.PullClosed: 593 + repoInfo.Stats.PullCount.Closed = int(countRes.Total) 594 + } 595 + } 596 + switch state { 597 + case models.PullOpen: 598 + repoInfo.Stats.PullCount.Open = int(res.Total) 599 + case models.PullMerged: 600 + repoInfo.Stats.PullCount.Merged = int(res.Total) 601 + case models.PullClosed: 602 + repoInfo.Stats.PullCount.Closed = int(res.Total) 603 + } 604 + 605 pulls, err = db.GetPulls( 606 s.db, 607 orm.FilterIn("id", res.Hits), ··· 700 701 s.pages.RepoPulls(w, pages.RepoPullsParams{ 702 LoggedInUser: s.oauth.GetMultiAccountUser(r), 703 + RepoInfo: repoInfo, 704 Pulls: pulls, 705 LabelDefs: defs, 706 FilteringBy: state,

History

1 round 1 comment
sign up or login to add to the discussion
pdewey.com submitted #0
1 commit
expand
3bc3a3f7
appview/pulls: fix search not updating count of pull requests
expand 1 comment
pull request successfully merged