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

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, ··· 571 569 } 572 570 totalPulls = int(res.Total) 573 571 l.Debug("searched pulls with indexer", "count", len(res.Hits)) 572 + 573 + // count matching pulls in the other states to display correct counts 574 + for _, other := range []models.PullState{models.PullOpen, models.PullMerged, models.PullClosed} { 575 + if other == state { 576 + continue 577 + } 578 + countRes, err := s.indexer.Search(r.Context(), models.PullSearchOptions{ 579 + Keyword: keyword, RepoAt: f.RepoAt().String(), State: other, 580 + Page: pagination.Page{Limit: 1}, 581 + }) 582 + if err != nil { 583 + continue 584 + } 585 + switch other { 586 + case models.PullOpen: 587 + repoInfo.Stats.PullCount.Open = int(countRes.Total) 588 + case models.PullMerged: 589 + repoInfo.Stats.PullCount.Merged = int(countRes.Total) 590 + case models.PullClosed: 591 + repoInfo.Stats.PullCount.Closed = int(countRes.Total) 592 + } 593 + } 594 + switch state { 595 + case models.PullOpen: 596 + repoInfo.Stats.PullCount.Open = int(res.Total) 597 + case models.PullMerged: 598 + repoInfo.Stats.PullCount.Merged = int(res.Total) 599 + case models.PullClosed: 600 + repoInfo.Stats.PullCount.Closed = int(res.Total) 601 + } 574 602 575 603 pulls, err = db.GetPulls( 576 604 s.db, ··· 700 668 701 669 s.pages.RepoPulls(w, pages.RepoPullsParams{ 702 670 LoggedInUser: s.oauth.GetMultiAccountUser(r), 703 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 671 + RepoInfo: repoInfo, 704 672 Pulls: pulls, 705 673 LabelDefs: defs, 706 674 FilteringBy: state,