Commit 924643198c924c19d0b468b27ee92077cefe7424

Authored by Dmitriy Zaporozhets
2 parents 7587a3b2 92de0faf

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

Fix timeout error while showing the network graph.
app/models/network/graph.rb
@@ -25,15 +25,7 @@ module Network @@ -25,15 +25,7 @@ module Network
25 def collect_commits 25 def collect_commits
26 refs_cache = build_refs_cache 26 refs_cache = build_refs_cache
27 27
28 - Grit::Commit.find_all(  
29 - @repo,  
30 - nil,  
31 - {  
32 - date_order: true,  
33 - max_count: self.class.max_count,  
34 - skip: count_to_display_commit_in_center  
35 - }  
36 - ) 28 + find_commits(count_to_display_commit_in_center)
37 .map do |commit| 29 .map do |commit|
38 # Decorate with app/model/network/commit.rb 30 # Decorate with app/model/network/commit.rb
39 Network::Commit.new(commit, refs_cache[commit.id]) 31 Network::Commit.new(commit, refs_cache[commit.id])
@@ -74,18 +66,47 @@ module Network @@ -74,18 +66,47 @@ module Network
74 66
75 # Skip count that the target commit is displayed in center. 67 # Skip count that the target commit is displayed in center.
76 def count_to_display_commit_in_center 68 def count_to_display_commit_in_center
77 - commit_index = Grit::Commit.find_all(@repo, nil, {date_order: true}).index do |c|  
78 - c.id == @commit.id 69 + offset = -1
  70 + skip = 0
  71 + while offset == -1
  72 + tmp_commits = find_commits(skip)
  73 + if tmp_commits.size > 0
  74 + index = tmp_commits.index do |c|
  75 + c.id == @commit.id
  76 + end
  77 +
  78 + if index
  79 + # Find the target commit
  80 + offset = index + skip
  81 + else
  82 + skip += self.class.max_count
  83 + end
  84 + else
  85 + # Cant't find the target commit in the repo.
  86 + offset = 0
  87 + end
79 end 88 end
80 89
81 - if commit_index && (self.class.max_count / 2 < commit_index) then 90 + if self.class.max_count / 2 < offset then
82 # get max index that commit is displayed in the center. 91 # get max index that commit is displayed in the center.
83 - commit_index - self.class.max_count / 2 92 + offset - self.class.max_count / 2
84 else 93 else
85 0 94 0
86 end 95 end
87 end 96 end
88 97
  98 + def find_commits(skip = 0)
  99 + Grit::Commit.find_all(
  100 + @repo,
  101 + nil,
  102 + {
  103 + date_order: true,
  104 + max_count: self.class.max_count,
  105 + skip: skip
  106 + }
  107 + )
  108 + end
  109 +
89 def commits_sort_by_ref 110 def commits_sort_by_ref
90 @commits.sort do |a,b| 111 @commits.sort do |a,b|
91 if include_ref?(a) 112 if include_ref?(a)
features/support/env.rb
@@ -28,8 +28,8 @@ require &#39;capybara/poltergeist&#39; @@ -28,8 +28,8 @@ require &#39;capybara/poltergeist&#39;
28 Capybara.javascript_driver = :poltergeist 28 Capybara.javascript_driver = :poltergeist
29 Spinach.hooks.on_tag("javascript") do 29 Spinach.hooks.on_tag("javascript") do
30 ::Capybara.current_driver = ::Capybara.javascript_driver 30 ::Capybara.current_driver = ::Capybara.javascript_driver
31 - ::Capybara.default_wait_time = 5  
32 end 31 end
  32 +Capybara.default_wait_time = 10
33 33
34 34
35 DatabaseCleaner.strategy = :truncation 35 DatabaseCleaner.strategy = :truncation
spec/features/projects_spec.rb
@@ -11,7 +11,7 @@ describe &quot;Projects&quot; do @@ -11,7 +11,7 @@ describe &quot;Projects&quot; do
11 end 11 end
12 12
13 it "should be correct path" do 13 it "should be correct path" do
14 - expect { click_link "Remove" }.to change {Project.count}.by(-1) 14 + expect { click_link "Remove project" }.to change {Project.count}.by(-1)
15 end 15 end
16 end 16 end
17 end 17 end
spec/features/security/project_access_spec.rb
@@ -230,14 +230,17 @@ describe &quot;Application access&quot; do @@ -230,14 +230,17 @@ describe &quot;Application access&quot; do
230 end 230 end
231 231
232 describe "GET /project_code/files" do 232 describe "GET /project_code/files" do
233 - subject { files_project_path(project) } 233 + pending("ProjectsController#files have been deleted.") do
234 234
235 - it { should be_allowed_for master }  
236 - it { should be_allowed_for reporter }  
237 - it { should be_denied_for :admin }  
238 - it { should be_denied_for guest }  
239 - it { should be_denied_for :user }  
240 - it { should be_denied_for :visitor } 235 + subject { files_project_path(project) }
  236 +
  237 + it { should be_allowed_for master }
  238 + it { should be_allowed_for reporter }
  239 + it { should be_denied_for :admin }
  240 + it { should be_denied_for guest }
  241 + it { should be_denied_for :user }
  242 + it { should be_denied_for :visitor }
  243 + end
241 end 244 end
242 end 245 end
243 end 246 end