[refs #579] some optimization by getting pull repo

This commit is contained in:
Alexander Machehin 2012-10-16 16:19:53 +06:00
parent b0604f89d1
commit 9579734506
4 changed files with 12 additions and 13 deletions

View File

@ -128,16 +128,15 @@ class Projects::PullRequestsController < Projects::BaseController
end end
def load_diff_commits_data def load_diff_commits_data
@repo = Grit::Repo.new(@pull.path)
@base_commit = @pull.common_ancestor @base_commit = @pull.common_ancestor
@head_commit = @repo.commits(@pull.head_branch).first @head_commit = @pull.repo.commits(@pull.head_branch).first
@commits = @repo.commits_between(@repo.commits(@pull.to_ref).first, @head_commit) @commits = @pull.repo.commits_between(@pull.repo.commits(@pull.to_ref).first, @head_commit)
@total_commits = @commits.count @total_commits = @commits.count
@commits = @commits.last(100) @commits = @commits.last(100)
@diff = @pull.diff @repo, @base_commit, @head_commit @diff = @pull.diff @pull.repo, @base_commit, @head_commit
@stats = @pull.diff_stats @repo, @base_commit, @head_commit @stats = @pull.diff_stats @pull.repo, @base_commit, @head_commit
@comments = @issue.comments @comments = @issue.comments
@commentable = @issue @commentable = @issue
end end

View File

@ -93,10 +93,8 @@ class Comment < ActiveRecord::Base
return true if params[:path].blank? && params[:line].blank? # not inline comment return true if params[:path].blank? && params[:line].blank? # not inline comment
self.data = {:path => params[:path], :line => params[:line]} self.data = {:path => params[:path], :line => params[:line]}
if commentable.class == Issue && pull = commentable.pull_request if commentable.class == Issue && pull = commentable.pull_request
repo = Grit::Repo.new(pull.path) to_commit, from_commit = pull.common_ancestor, pull.repo.commits(pull.head_branch).first
to_commit, from_commit = pull.common_ancestor, repo.commits(pull.head_branch).first diff = pull.diff pull.repo, to_commit, from_commit
diff = pull.diff repo, to_commit, from_commit
diff_path = diff.select {|d| d.a_path == params[:path]} diff_path = diff.select {|d| d.a_path == params[:path]}
return false unless actual_inline_comment?(diff, true) return false unless actual_inline_comment?(diff, true)

View File

@ -96,7 +96,6 @@ class PullRequest < ActiveRecord::Base
def common_ancestor def common_ancestor
return @common_ancestor if @common_ancestor return @common_ancestor if @common_ancestor
repo = Grit::Repo.new(path)
base_commit = repo.commits(to_ref).first base_commit = repo.commits(to_ref).first
head_commit = repo.commits(head_branch).first head_commit = repo.commits(head_branch).first
@common_ancestor = repo.commit(repo.git.merge_base({}, base_commit, head_commit)) || base_commit @common_ancestor = repo.commit(repo.git.merge_base({}, base_commit, head_commit)) || base_commit
@ -147,6 +146,10 @@ class PullRequest < ActiveRecord::Base
end end
end end
def repo
return @repo if @repo.present? #&& !id_changed?
@repo = Grit::Repo.new path
end
protected protected
def merge def merge
@ -204,8 +207,7 @@ class PullRequest < ActiveRecord::Base
def update_inline_comments def update_inline_comments
if self.comments.count > 0 if self.comments.count > 0
repo = Grit::Repo.new self.path diff = self.diff self.repo, self.common_ancestor, repo.commits(self.head_branch).first
diff = self.diff repo, self.common_ancestor, repo.commits(self.head_branch).first
end end
self.comments.each do |c| self.comments.each do |c|
if c.data.present? # maybe need add new column 'actual'? if c.data.present? # maybe need add new column 'actual'?

View File

@ -6,5 +6,5 @@
- if pull_diff.b_path.present? - if pull_diff.b_path.present?
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path) .r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path)
.clear .clear
-if pull_diff.diff.present? && !(Grit::Repo.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary? -if pull_diff.diff.present? && !(@pull.repo.tree(commit_id) / pull_diff.b_path).binary?
.diff_data=render_diff(pull_diff, pull_diff_counter, @comments) .diff_data=render_diff(pull_diff, pull_diff_counter, @comments)