Monorepo for Tangled

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 <p@pdewey.com>

authored by

pdewey.com and committed by tangled.org 49f26937 e1783620

+33 -1
+33 -1
appview/pulls/pulls.go
··· 553 553 554 554 keyword := params.Get("q") 555 555 556 + repoInfo := s.repoResolver.GetRepoInfo(r, user) 557 + 556 558 var pulls []*models.Pull 557 559 searchOpts := models.PullSearchOptions{ 558 560 Keyword: keyword, ··· 569 571 } 570 572 totalPulls = int(res.Total) 571 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 + } 572 604 573 605 pulls, err = db.GetPulls( 574 606 s.db, ··· 668 700 669 701 s.pages.RepoPulls(w, pages.RepoPullsParams{ 670 702 LoggedInUser: s.oauth.GetMultiAccountUser(r), 671 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 703 + RepoInfo: repoInfo, 672 704 Pulls: pulls, 673 705 LabelDefs: defs, 674 706 FilteringBy: state,