From dd140ea717a230ff04786da95bf89f8056425115 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 22 Feb 2023 17:53:46 +0000 Subject: [PATCH] utils/github/api: Smarter pagination in `paginate_rest` - The `API_MAX_PAGES` value is 50, so for pages 1 to 50, the `paginate_rest` method was making an API call even if there was no data past, for example, page 8. - This made `brew contributions --user=issyl0` take 11 minutes, since we made 50 API calls _per repo_ even if it was unnecessary, burning down our API allowance. - Instead, stop looping if we detect that there's no data in `result`. - This probably needs more testing for other parts of Homebrew that rely on `paginate_rest` and the different shapes of data it outputs. --- Library/Homebrew/utils/github/api.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index 2dd8bfe408..a49773a167 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -256,6 +256,8 @@ module GitHub def paginate_rest(url, additional_query_params: nil, per_page: 100) (1..API_MAX_PAGES).each do |page| result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}") + break if result.blank? + yield(result, page) end end