3

trying to query the github api with octokit, I have the following function which takes 3-4 minutes, does anyone see an obvious problem for why it takes so slow ? I'm trying to find the top contributors within an organization, by looping through each repo in the organization, and from there checking the top contributors for the repo and afterwards sorting.

def get_top_internal(client)
    repos = client.org_repos(params[:org])
    contributor_count_hash = Hash.new(0)
    contributors = []
    repos.each do |repo|
      contributors = client.contributors(repo.full_name,anon=true,per_page:10)
      contributors.each do |contributor|
        contributor_count_hash[contributor.login] += contributor.contributions
      end
    end
    sorted = contributor_count_hash.sort_by {|arr| arr[1]}
    sorted = sorted.slice!(-5..-1)

    user_names = sorted.map {|arr| arr[0]}
    debugger
    return_array = contributors.select {|user| user_names.include? user[:login]}
  end
sco
  • 367
  • 3
  • 14

0 Answers0