Skip to content

Commit

Permalink
Performance improvement - cache comments retrieved from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Sep 10, 2014
1 parent e498de7 commit d8064e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 0.3.0

### New features

### Changes

* [#29](https://github.com/mmozuras/pronto/issues/29): Be compatible and depend on rugged '0.21.0'.
* Performance improvement - use Rugged::Blame instead of one provided by Grit.
* Performance improvement - cache comments retrieved from GitHub.

### Bugs fixed
10 changes: 8 additions & 2 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module Pronto
class Github
def initialize
@comment_cache = {}
end

def commit_comments(repo, sha)
client.commit_comments(repo, sha).map do |comment|
Comment.new(repo, sha, comment.body, comment.path, comment.body)
@comment_cache["#{repo}/#{sha}"] ||= begin
client.commit_comments(repo, sha).map do |comment|
Comment.new(repo, sha, comment.body, comment.path, comment.body)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/github_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Formatter
specify do
Octokit::Client.any_instance
.should_receive(:commit_comments)
.twice
.once
.and_return([])

Octokit::Client.any_instance
Expand Down
27 changes: 27 additions & 0 deletions spec/pronto/github_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

module Pronto
describe Github do
let(:github) { Github.new }

describe '#commit_comments' do
subject { github.commit_comments(repo, sha) }

context 'three requests for same comments' do
let(:repo) { 'mmozuras/pronto' }
let(:sha) { '61e4bef' }

specify do
Octokit::Client.any_instance
.should_receive(:commit_comments)
.once
.and_return([])

subject
subject
subject
end
end
end
end
end

0 comments on commit d8064e9

Please sign in to comment.