Skip to content

Conversation

@unhappychoice
Copy link

@unhappychoice unhappychoice commented Feb 8, 2026

Fixes #112

Summary

The GraphQL user search uses sort:followers-desc in the query string, but GitHub does not support the sort:followers qualifier for user search. This causes non-deterministic results and missing users in the rankings.

Changes

Replaces the single GraphQL search query with a two-step approach:

  1. REST API GET /search/users?sort=followers&order=desc for collecting user logins — the REST API officially supports sort=followers and returns correctly sorted results with no duplicates
  2. GraphQL user(login:) batch queries (10 users/batch) for fetching detailed data (contributions, organizations, follower counts)

Other changes

  • MinFollowers field added to UserSearchQuery and QueryPreset — the worldwide preset uses minFollowers: 1000 to narrow the search scope. Without this filter, the REST API search may hit GitHub's time limit and return partial results (the response's incomplete_results field would be true), since worldwide has 160M+ users.
  • minFollowers() fix — computes the actual minimum across all users instead of using the last user's follower count
  • Exclude claude account — the Anthropic Claude Code co-author account causes GitHub GraphQL to return 504 on contributionsCollection due to its massive co-authored commit volume
  • Exponential backoff retry for GraphQL batch errors
  • Rate limit delays (2s) between REST pages and GraphQL batches to avoid secondary rate limits

Testing

Verified with production settings (consider=1000, amount=256):

  • Japan preset: 1000 users fetched, 0 duplicates, all REST API pages returned complete results, top user keijiro (23,372 followers) → bottom user ucan-lab (214 followers)
  • Worldwide preset: 999 users fetched (claude excluded), 0 duplicates, all REST API pages returned complete results, top user torvalds (283,302 followers) → bottom user Aakashdeveloper (4,489 followers)

Files changed

File Change
github/github.go Rewrite SearchUsers() to use REST + GraphQL two-step approach
presets.go Add minFollowers field to QueryPreset; set minFollowers: 1000 for worldwide
top/top.go Add MinFollowers to Options struct; pass through to UserSearchQuery
main.go Read preset.minFollowers and pass to top.Options

The original implementation uses GraphQL search with sort:followers-desc
in the query string, but GitHub does not support the sort qualifier for
user search. This causes non-deterministic results and missing users.

This commit replaces the user search with a two-step approach:
1. REST API GET /search/users?sort=followers (officially supported)
2. GraphQL user(login:) batch queries for detailed data

Other changes:
- Add MinFollowers field to UserSearchQuery and QueryPreset
- Set minFollowers=1000 for the worldwide preset to avoid incomplete results
- Exclude the "claude" account (Anthropic co-author bot) which causes
  GitHub GraphQL to return 504 on contributionsCollection
- Add exponential backoff retry for GraphQL batch errors
- Add rate limit delays between API requests
@unhappychoice
Copy link
Author

unhappychoice commented Feb 8, 2026

BTW, thank you for maintaining this project! I really appreciate the work you've put into it.

@ashkulz
Copy link
Owner

ashkulz commented Feb 9, 2026

@unhappychoice thank you for the fanastic analysis! I'm a bit tied up right now, I'll review this on Wednesday.

I'm standing on the shouders of giants -- @lauripiispanen did most of the work, and I'm just keeping the lights running 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User search returns incorrect results because GraphQL search does not support sort:followers for users

2 participants