Fixed: performance issue on RepositoriesController#revisions when a changeset has a great number of changes (eg. 100,000).
Also added pagination for changes on changeset details view. git-svn-id: http://redmine.rubyforge.org/svn/trunk@535 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
777c9acae8
commit
bb1fccb7b7
|
@ -49,7 +49,7 @@ class RepositoriesController < ApplicationController
|
||||||
show_error and return unless @entry
|
show_error and return unless @entry
|
||||||
end
|
end
|
||||||
@repository.changesets_with_path @path do
|
@repository.changesets_with_path @path do
|
||||||
@changeset_count = @repository.changesets.count
|
@changeset_count = @repository.changesets.count(:select => "DISTINCT #{Changeset.table_name}.id")
|
||||||
@changeset_pages = Paginator.new self, @changeset_count,
|
@changeset_pages = Paginator.new self, @changeset_count,
|
||||||
25,
|
25,
|
||||||
params['page']
|
params['page']
|
||||||
|
@ -71,6 +71,13 @@ class RepositoriesController < ApplicationController
|
||||||
def revision
|
def revision
|
||||||
@changeset = @repository.changesets.find_by_revision(@rev)
|
@changeset = @repository.changesets.find_by_revision(@rev)
|
||||||
show_error and return unless @changeset
|
show_error and return unless @changeset
|
||||||
|
@changes_count = @changeset.changes.size
|
||||||
|
@changes_pages = Paginator.new self, @changes_count, 150, params['page']
|
||||||
|
@changes = @changeset.changes.find(:all,
|
||||||
|
:limit => @changes_pages.items_per_page,
|
||||||
|
:offset => @changes_pages.current.offset)
|
||||||
|
|
||||||
|
render :action => "revision", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff
|
def diff
|
||||||
|
|
|
@ -40,7 +40,9 @@ class Repository < ActiveRecord::Base
|
||||||
path = "/#{path}%"
|
path = "/#{path}%"
|
||||||
path = url.gsub(/^#{root_url}/, '') + path if root_url && root_url != url
|
path = url.gsub(/^#{root_url}/, '') + path if root_url && root_url != url
|
||||||
path.squeeze!("/")
|
path.squeeze!("/")
|
||||||
Changeset.with_scope(:find => { :include => :changes, :conditions => ["#{Change.table_name}.path LIKE ?", path] }) do
|
# Custom select and joins is done to allow conditions on changes table without loading associated Change objects
|
||||||
|
# Required for changesets with a great number of changes (eg. 100,000)
|
||||||
|
Changeset.with_scope(:find => { :select => "DISTINCT #{Changeset.table_name}.*", :joins => "LEFT OUTER JOIN #{Change.table_name} ON #{Change.table_name}.changeset_id = #{Changeset.table_name}.id", :conditions => ["#{Change.table_name}.path LIKE ?", path] }) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<p><%= link_to(l(:label_view_diff), :action => 'diff', :id => @project, :path => "", :rev => @changeset.revision) if @changeset.changes.any? %></p>
|
<p><%= link_to(l(:label_view_diff), :action => 'diff', :id => @project, :path => "", :rev => @changeset.revision) if @changeset.changes.any? %></p>
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @changeset.changes.each do |change| %>
|
<% @changes.each do |change| %>
|
||||||
<tr class="<%= cycle 'odd', 'even' %>">
|
<tr class="<%= cycle 'odd', 'even' %>">
|
||||||
<td><div class="square action_<%= change.action %>"></div> <%= change.path %></td>
|
<td><div class="square action_<%= change.action %>"></div> <%= change.path %></td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
|
@ -40,8 +40,9 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p><%= lwr(:label_modification, @changeset.changes.length) %></p>
|
<p><%= pagination_links_full @changes_pages, :rev => @changeset.revision %>
|
||||||
|
[ <%= @changes_pages.current.first_item %> - <%= @changes_pages.current.last_item %> / <%= @changes_count %> ]</p>
|
||||||
|
|
||||||
<% content_for :header_tags do %>
|
<% content_for :header_tags do %>
|
||||||
<%= stylesheet_link_tag "scm" %>
|
<%= stylesheet_link_tag "scm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
---
|
||||||
|
changes_001:
|
||||||
|
id: 1
|
||||||
|
changeset_id: 100
|
||||||
|
action: A
|
||||||
|
path: /test/some/path/in/the/repo
|
||||||
|
from_path:
|
||||||
|
from_revision:
|
||||||
|
changes_002:
|
||||||
|
id: 2
|
||||||
|
changeset_id: 100
|
||||||
|
action: A
|
||||||
|
path: /test/some/path/elsewhere/in/the/repo
|
||||||
|
from_path:
|
||||||
|
from_revision:
|
||||||
|
|
|
@ -18,7 +18,11 @@
|
||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
class RepositoryTest < Test::Unit::TestCase
|
class RepositoryTest < Test::Unit::TestCase
|
||||||
fixtures :projects, :repositories, :issues, :issue_statuses, :changesets
|
fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@repository = Project.find(1).repository
|
||||||
|
end
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
repository = Repository.new(:project => Project.find(2))
|
repository = Repository.new(:project => Project.find(2))
|
||||||
|
@ -33,10 +37,9 @@ class RepositoryTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cant_change_url
|
def test_cant_change_url
|
||||||
repository = Project.find(1).repository
|
url = @repository.url
|
||||||
url = repository.url
|
@repository.url = "svn://anotherhost"
|
||||||
repository.url = "svn://anotherhost"
|
assert_equal url, @repository.url
|
||||||
assert_equal url, repository.url
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scan_changesets_for_issue_ids
|
def test_scan_changesets_for_issue_ids
|
||||||
|
@ -56,4 +59,12 @@ class RepositoryTest < Test::Unit::TestCase
|
||||||
# ignoring commits referencing an issue of another project
|
# ignoring commits referencing an issue of another project
|
||||||
assert_equal [], Issue.find(4).changesets
|
assert_equal [], Issue.find(4).changesets
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_changesets_with_path
|
||||||
|
@repository.changesets_with_path '/some/path' do
|
||||||
|
assert_equal 1, @repository.changesets.count(:select => "DISTINCT #{Changeset.table_name}.id")
|
||||||
|
changesets = @repository.changesets.find(:all)
|
||||||
|
assert_equal 1, changesets.size
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue