From 46fa92187d6c076619e9cd58877e03c6d15a1f03 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 19 Mar 2013 10:00:29 +0900 Subject: [PATCH 1/4] Refactor: removing duplicate code. --- app/models/network/graph.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 074ec371..16512b90 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -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,7 +66,7 @@ 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| + commit_index = find_commits.index do |c| c.id == @commit.id end @@ -86,6 +78,18 @@ module Network 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) From e00e54b69ca7cd1c4cfbb726b87372c479ff8b73 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 19 Mar 2013 10:22:55 +0900 Subject: [PATCH 2/4] Fix timeout error while showing the very large repo like git repo. --- app/models/network/graph.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 16512b90..4b1abf52 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -66,13 +66,30 @@ module Network # Skip count that the target commit is displayed in center. def count_to_display_commit_in_center - commit_index = find_commits.index do |c| - c.id == @commit.id + 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 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 commit_index && (self.class.max_count / 2 < commit_index) then + 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 From fc66c18349c01b5d5d07b9780d54ad12f42112de Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 19 Mar 2013 12:53:12 +0900 Subject: [PATCH 3/4] Fix travis failed randomly by timeout. --- features/support/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index f6f88955..90a61dd1 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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 From 92de0faf6e86d7fed33bc8989e3f2147c16450dd Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 19 Mar 2013 13:46:07 +0900 Subject: [PATCH 4/4] Fix spec errors. --- spec/features/projects_spec.rb | 2 +- spec/features/security/project_access_spec.rb | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index 7bc48260..1ffc28bf 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -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 diff --git a/spec/features/security/project_access_spec.rb b/spec/features/security/project_access_spec.rb index a3517510..a871cf01 100644 --- a/spec/features/security/project_access_spec.rb +++ b/spec/features/security/project_access_spec.rb @@ -230,14 +230,17 @@ describe "Application access" do end describe "GET /project_code/files" do - subject { files_project_path(project) } + pending("ProjectsController#files have been deleted.") do - it { should be_allowed_for master } - it { should be_allowed_for reporter } - it { should be_denied_for :admin } - it { should be_denied_for guest } - it { should be_denied_for :user } - it { should be_denied_for :visitor } + subject { files_project_path(project) } + + it { should be_allowed_for master } + it { should be_allowed_for reporter } + it { should be_denied_for :admin } + it { should be_denied_for guest } + it { should be_denied_for :user } + it { should be_denied_for :visitor } + end end end end