@@ -1765,7 +1765,7 @@ func (s *Server) processRepoSampleWithProgress(ctx context.Context, req *RepoSam
17651765 PR : 0 ,
17661766 Owner : req .Owner ,
17671767 Repo : req .Repo ,
1768- Progress : "Querying GitHub for PRs..." ,
1768+ Progress : fmt . Sprintf ( "Querying GitHub GraphQL API for %s/%s PRs (last %d days) ..." , req . Owner , req . Repo , req . Days ) ,
17691769 }))
17701770
17711771 // Start keep-alive to prevent client timeout during GraphQL query
@@ -1890,7 +1890,7 @@ func (s *Server) processOrgSampleWithProgress(ctx context.Context, req *OrgSampl
18901890 logSSEError (ctx , s .logger , sendSSE (writer , ProgressUpdate {
18911891 Type : "fetching" ,
18921892 PR : 0 ,
1893- Progress : "Querying GitHub for PRs..." ,
1893+ Progress : fmt . Sprintf ( "Querying GitHub Search API for %s org PRs (last %d days) ..." , req . Org , req . Days ) ,
18941894 }))
18951895
18961896 // Start keep-alive to prevent client timeout during GraphQL query
@@ -1965,29 +1965,14 @@ func (s *Server) processOrgSampleWithProgress(ctx context.Context, req *OrgSampl
19651965 // Count unique authors across all PRs (not just samples)
19661966 totalAuthors := github .CountUniqueAuthors (prs )
19671967
1968- // Count open PRs across all unique repos in the organization
1969- uniqueRepos := make (map [string ]bool )
1970- for _ , pr := range prs {
1971- repoKey := pr .Owner + "/" + pr .Repo
1972- uniqueRepos [repoKey ] = true
1973- }
1974-
1975- totalOpenPRs := 0
1976- for repoKey := range uniqueRepos {
1977- parts := strings .SplitN (repoKey , "/" , 2 )
1978- if len (parts ) != 2 {
1979- continue
1980- }
1981- owner , repo := parts [0 ], parts [1 ]
1982- //nolint:contextcheck // Using background context intentionally to prevent client timeout from canceling work
1983- openCount , err := github .CountOpenPRsInRepo (workCtx , owner , repo , token )
1984- if err != nil {
1985- s .logger .WarnContext (ctx , "Failed to count open PRs for repo" , "repo" , repoKey , errorKey , err )
1986- continue
1987- }
1988- totalOpenPRs += openCount
1968+ // Count open PRs across the entire organization with a single GraphQL query
1969+ //nolint:contextcheck // Using background context intentionally to prevent client timeout from canceling work
1970+ totalOpenPRs , err := github .CountOpenPRsInOrg (workCtx , req .Org , token )
1971+ if err != nil {
1972+ s .logger .WarnContext (ctx , "Failed to count open PRs for organization" , "org" , req .Org , errorKey , err )
1973+ totalOpenPRs = 0 // Continue with 0 if we can't get the count
19891974 }
1990- s .logger .InfoContext (ctx , "Counted total open PRs across organization" , "open_prs" , totalOpenPRs , "repos " , len ( uniqueRepos ) )
1975+ s .logger .InfoContext (ctx , "Counted total open PRs across organization" , "open_prs" , totalOpenPRs , "org " , req . Org )
19911976
19921977 // Extrapolate costs from samples
19931978 extrapolated := cost .ExtrapolateFromSamples (breakdowns , len (prs ), totalAuthors , totalOpenPRs , actualDays , cfg )
0 commit comments