[refs #579] some optimization by getting pull repo
This commit is contained in:
parent
b0604f89d1
commit
9579734506
|
@ -128,16 +128,15 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
end
|
||||
|
||||
def load_diff_commits_data
|
||||
@repo = Grit::Repo.new(@pull.path)
|
||||
@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
|
||||
@commits = @commits.last(100)
|
||||
|
||||
@diff = @pull.diff @repo, @base_commit, @head_commit
|
||||
@stats = @pull.diff_stats @repo, @base_commit, @head_commit
|
||||
@diff = @pull.diff @pull.repo, @base_commit, @head_commit
|
||||
@stats = @pull.diff_stats @pull.repo, @base_commit, @head_commit
|
||||
@comments = @issue.comments
|
||||
@commentable = @issue
|
||||
end
|
||||
|
|
|
@ -93,10 +93,8 @@ class Comment < ActiveRecord::Base
|
|||
return true if params[:path].blank? && params[:line].blank? # not inline comment
|
||||
self.data = {:path => params[:path], :line => params[:line]}
|
||||
if commentable.class == Issue && pull = commentable.pull_request
|
||||
repo = Grit::Repo.new(pull.path)
|
||||
to_commit, from_commit = pull.common_ancestor, repo.commits(pull.head_branch).first
|
||||
|
||||
diff = pull.diff repo, to_commit, from_commit
|
||||
to_commit, from_commit = pull.common_ancestor, pull.repo.commits(pull.head_branch).first
|
||||
diff = pull.diff pull.repo, to_commit, from_commit
|
||||
diff_path = diff.select {|d| d.a_path == params[:path]}
|
||||
return false unless actual_inline_comment?(diff, true)
|
||||
|
||||
|
|
|
@ -96,7 +96,6 @@ class PullRequest < ActiveRecord::Base
|
|||
|
||||
def common_ancestor
|
||||
return @common_ancestor if @common_ancestor
|
||||
repo = Grit::Repo.new(path)
|
||||
base_commit = repo.commits(to_ref).first
|
||||
head_commit = repo.commits(head_branch).first
|
||||
@common_ancestor = repo.commit(repo.git.merge_base({}, base_commit, head_commit)) || base_commit
|
||||
|
@ -147,6 +146,10 @@ class PullRequest < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def repo
|
||||
return @repo if @repo.present? #&& !id_changed?
|
||||
@repo = Grit::Repo.new path
|
||||
end
|
||||
protected
|
||||
|
||||
def merge
|
||||
|
@ -204,8 +207,7 @@ class PullRequest < ActiveRecord::Base
|
|||
|
||||
def update_inline_comments
|
||||
if self.comments.count > 0
|
||||
repo = Grit::Repo.new self.path
|
||||
diff = self.diff repo, self.common_ancestor, repo.commits(self.head_branch).first
|
||||
diff = self.diff self.repo, self.common_ancestor, repo.commits(self.head_branch).first
|
||||
end
|
||||
self.comments.each do |c|
|
||||
if c.data.present? # maybe need add new column 'actual'?
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
- 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)
|
||||
.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)
|
||||
|
|
Loading…
Reference in New Issue