Merge pull request #3252 from hiroponz/fix-timeout-large-repository

Fix timeout error while showing the network graph.
This commit is contained in:
Dmitriy Zaporozhets 2013-03-18 23:17:52 -07:00
commit 924643198c
4 changed files with 46 additions and 22 deletions

View file

@ -25,15 +25,7 @@ module Network
def collect_commits
refs_cache = build_refs_cache
Grit::Commit.find_all(
@repo,
nil,
{
date_order: true,
max_count: self.class.max_count,
skip: count_to_display_commit_in_center
}
)
find_commits(count_to_display_commit_in_center)
.map do |commit|
# Decorate with app/model/network/commit.rb
Network::Commit.new(commit, refs_cache[commit.id])
@ -74,18 +66,47 @@ module Network
# Skip count that the target commit is displayed in center.
def count_to_display_commit_in_center
commit_index = Grit::Commit.find_all(@repo, nil, {date_order: true}).index do |c|
offset = -1
skip = 0
while offset == -1
tmp_commits = find_commits(skip)
if tmp_commits.size > 0
index = tmp_commits.index do |c|
c.id == @commit.id
end
if commit_index && (self.class.max_count / 2 < commit_index) then
if index
# Find the target commit
offset = index + skip
else
skip += self.class.max_count
end
else
# Cant't find the target commit in the repo.
offset = 0
end
end
if self.class.max_count / 2 < offset then
# get max index that commit is displayed in the center.
commit_index - self.class.max_count / 2
offset - self.class.max_count / 2
else
0
end
end
def find_commits(skip = 0)
Grit::Commit.find_all(
@repo,
nil,
{
date_order: true,
max_count: self.class.max_count,
skip: skip
}
)
end
def commits_sort_by_ref
@commits.sort do |a,b|
if include_ref?(a)

View file

@ -28,8 +28,8 @@ require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Spinach.hooks.on_tag("javascript") do
::Capybara.current_driver = ::Capybara.javascript_driver
::Capybara.default_wait_time = 5
end
Capybara.default_wait_time = 10
DatabaseCleaner.strategy = :truncation

View file

@ -11,7 +11,7 @@ describe "Projects" do
end
it "should be correct path" do
expect { click_link "Remove" }.to change {Project.count}.by(-1)
expect { click_link "Remove project" }.to change {Project.count}.by(-1)
end
end
end

View file

@ -230,6 +230,8 @@ describe "Application access" do
end
describe "GET /project_code/files" do
pending("ProjectsController#files have been deleted.") do
subject { files_project_path(project) }
it { should be_allowed_for master }
@ -240,4 +242,5 @@ describe "Application access" do
it { should be_denied_for :visitor }
end
end
end
end