Commit 197f3c6b5b396f58d270cc5c025537ac4cfc6be5
Committed by
Daniela Feitosa
1 parent
44297261
Exists in
master
and in
29 other branches
Makes faster db consult for users list download
* In app/controller/admin/users_controller.rb uses a User.find() method call that uses a :include argument to load the needed Persons with a single sql instead of one sql consult per user. * Only call User.find() if the format is csv or xml, to avoid making the huge sql consult every time the user loads the page. * With this change, the downloading time of a users list on csv format decreased 63%, while on xml format decreased 30%. * I've got no guarantee it's enough time to avoid timeout in production server, though. * Not tested on debian. (ActionItem2241)
Showing
1 changed file
with
2 additions
and
1 deletions
Show diff stats
app/controllers/admin/users_controller.rb
... | ... | @@ -3,10 +3,10 @@ class UsersController < AdminController |
3 | 3 | protect 'manage_environment_users', :environment |
4 | 4 | |
5 | 5 | def index |
6 | - @users = environment.users | |
7 | 6 | respond_to do |format| |
8 | 7 | format.html |
9 | 8 | format.xml do |
9 | + @users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person]) | |
10 | 10 | render :xml => @users.to_xml( |
11 | 11 | :skip_types => true, |
12 | 12 | :only => %w[email login created_at updated_at], |
... | ... | @@ -14,6 +14,7 @@ class UsersController < AdminController |
14 | 14 | ) |
15 | 15 | end |
16 | 16 | format.csv do |
17 | + @users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person]) | |
17 | 18 | render :template => "users/index_csv.rhtml", :content_type => 'text/csv', :layout => false |
18 | 19 | end |
19 | 20 | end | ... | ... |