https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Desprès <nicolas.despres(a)lrde.epita.fr>
Improve benchmark list request.
* web/ranch/test/functional/benches_controller_test.rb: Test that the
bench id is provided.
* web/ranch/app/controllers/benches_controller.rb: Use SQL request
rather than Ruby code in order to improve request efficiency. Provide
the bench id to the view.
* web/ranch/app/views/benches/list.rhtml: Adapt to the change in the
controller.
app/controllers/benches_controller.rb | 10 +++++-----
app/views/benches/list.rhtml | 7 ++++---
test/functional/benches_controller_test.rb | 5 +++--
3 files changed, 12 insertions(+), 10 deletions(-)
Index: web/ranch/test/functional/benches_controller_test.rb
--- web/ranch/test/functional/benches_controller_test.rb (revision 13)
+++ web/ranch/test/functional/benches_controller_test.rb (working copy)
@@ -21,10 +21,11 @@
assert_template 'list'
assert_not_nil assigns(:project)
- assert_not_nil assigns(:benches_name)
+ assert_not_nil assigns(:benches)
+ assert_not_nil assigns(:benches).id
assert_equal(1,
- (assigns(:benches_name).find_all{|x| x == 'determinize'}).size,
+ (assigns(:benches).find_all{|x| x.name == 'determinize'}).size,
'there is duplicated benches name')
end
end
Index: web/ranch/app/controllers/benches_controller.rb
--- web/ranch/app/controllers/benches_controller.rb (revision 13)
+++ web/ranch/app/controllers/benches_controller.rb (working copy)
@@ -4,11 +4,11 @@
def list
@project = Project.find_by_id(@params[:project_id])
- @benches_name = Bench.find_all_by_project_id((a)project.id).collect do |x|
- x.name
- end
- @benches_name.uniq!
- @benches_name.sort!
+ @benches = Bench.find_by_sql "SELECT id, name " +
+ "FROM benches " +
+ "WHERE project_id = #{(a)project.id} " +
+ "GROUP BY name " +
+ "ORDER BY name"
end
end
Index: web/ranch/app/views/benches/list.rhtml
--- web/ranch/app/views/benches/list.rhtml (revision 13)
+++ web/ranch/app/views/benches/list.rhtml (working copy)
@@ -7,13 +7,14 @@
<p>
<center>
<table>
- <% for bench_name in @benches_name %>
+ <% for bench in @benches %>
<tr>
<td>
- <%= link_to bench_name, :controller => "graph_form",
+ <%= link_to bench.name, :controller => "graph_form",
:action => "index",
:project_id => @project.id,
- :bench_name => bench_name %>
+ :bench_id => bench.id,
+ :bench_name => bench.name %>
</td>
</tr>
<% end %>