Skip to content

Commit

Permalink
Merge pull request github-changelog-generator#653 from hunner/fix_iss…
Browse files Browse the repository at this point in the history
…ue_threading

Remove threading and use caching
  • Loading branch information
olleolleolle authored May 16, 2018
2 parents 7fe9adb + 1876043 commit 984ee50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
28 changes: 9 additions & 19 deletions lib/github_changelog_generator/generator/generator_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,24 @@ def fetch_events_for_issues_and_pr
# Async fetching of all tags dates
def fetch_tags_dates(tags)
print "Fetching tag dates...\r" if options[:verbose]
# Async fetching tags:
threads = []
i = 0
all = tags.count
tags.each do |tag|
print " \r"
threads << Thread.new do
get_time_of_tag(tag)
print "Fetching tags dates: #{i + 1}/#{all}\r" if options[:verbose]
i += 1
end
get_time_of_tag(tag)
i += 1
end
threads.each(&:join)
puts "Fetching tags dates: #{i}" if options[:verbose]
puts "Fetching tags dates: #{i}/#{tags.count}" if options[:verbose]
end

# Find correct closed dates, if issues was closed by commits
def detect_actual_closed_dates(issues)
print "Fetching closed dates for issues...\r" if options[:verbose]

issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
threads = []
issues_slice.each do |issue|
threads << Thread.new { find_closed_date_by_commit(issue) }
end
threads.each(&:join)
i = 0
issues.each do |issue|
find_closed_date_by_commit(issue)
i += 1
end
puts "Fetching closed dates for issues: Done!" if options[:verbose]
puts "Fetching closed dates for issues: #{i}/#{issues.count}" if options[:verbose]
end

# Adds a key "first_occurring_tag" to each PR with a value of the oldest
Expand Down Expand Up @@ -190,7 +180,7 @@ def set_date_from_event(event, issue)
issue["actual_date"] = issue["closed_at"]
else
begin
commit = @fetcher.fetch_commit(event)
commit = @fetcher.fetch_commit(event["commit_id"])
issue["actual_date"] = commit["commit"]["author"]["date"]

# issue['actual_date'] = commit['author']['date']
Expand Down
9 changes: 5 additions & 4 deletions lib/github_changelog_generator/octo_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def fetch_comments_async(prs)
#
# @return [Time] time of specified tag
def fetch_date_of_tag(tag)
commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) }
commit_data = fetch_commit(tag["commit"]["sha"])
commit_data = stringify_keys_deep(commit_data.to_hash)

commit_data["commit"]["committer"]["date"]
Expand All @@ -260,17 +260,18 @@ def fetch_compare(older, newer)

# Fetch commit for specified event
#
# @param [String] commit_id the SHA of a commit to fetch
# @return [Hash]
def fetch_commit(event)
def fetch_commit(commit_id)
found = commits.find do |commit|
commit["sha"] == event["commit_id"]
commit["sha"] == commit_id
end
if found
stringify_keys_deep(found.to_hash)
else
# cache miss; don't add to @commits because unsure of order.
check_github_response do
commit = @client.commit(user_project, event["commit_id"])
commit = @client.commit(user_project, commit_id)
commit = stringify_keys_deep(commit.to_hash)
commit
end
Expand Down

0 comments on commit 984ee50

Please sign in to comment.