MCPcopy Create free account
hub / github.com/cli/cli / fetchPrimaryPages

Function fetchPrimaryPages

pkg/cmd/skills/search/search.go:747–777  ·  view source on GitHub ↗

fetchPrimaryPages fetches enough API pages from GitHub Code Search to cover the requested display page, accounting for filtering losses.

(client *api.Client, host, query string, displayPage, displayLimit int)

Source from the content-addressed store, hash-verified

745// fetchPrimaryPages fetches enough API pages from GitHub Code Search to
746// cover the requested display page, accounting for filtering losses.
747func fetchPrimaryPages(client *api.Client, host, query string, displayPage, displayLimit int) ([]codeSearchItem, int, error) {
748 // Over-fetch to account for deduplication + filtering losses.
749 // The Code Search API is rate-limited at 10 req/min, so we keep
750 // page fetching conservative. Two pages (200 results) provides a
751 // good buffer for typical filter rates while staying well within
752 // the rate-limit budget.
753 needed := displayPage * displayLimit * 3
754 numPages := max((needed+searchPageSize-1)/searchPageSize, 1)
755 maxAPIPages := maxResults / searchPageSize
756 if numPages > maxAPIPages {
757 numPages = maxAPIPages
758 }
759
760 var allItems []codeSearchItem
761 var totalCount int
762 for p := 1; p <= numPages; p++ {
763 result, err := executeSearch(client, host, query, p, searchPageSize)
764 if err != nil {
765 if p == 1 {
766 return nil, 0, err
767 }
768 break // partial results from earlier pages are OK
769 }
770 allItems = append(allItems, result.Items...)
771 totalCount = result.TotalCount
772 if len(result.Items) < searchPageSize {
773 break // no more results available
774 }
775 }
776 return allItems, totalCount, nil
777}
778
779// deduplicateResults extracts unique (repo, namespace, skill name) triples from code search hits.
780func deduplicateResults(items []codeSearchItem) []skillResult {

Callers 1

searchByKeywordFunction · 0.85

Calls 1

executeSearchFunction · 0.85

Tested by

no test coverage detected