Patch #23378

Speedup Project Settings with many members

Added by Victor Campos over 1 year ago. Updated about 1 year ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:


Target version:-


There is a .sort in _members.html.erb partial that take a lot of time for project that have more than 12s to execute, so I change for .order('roles.builtin, roles.position, users.firstname, users.lastname')

- members =, :roles, :principal).to_a.sort
+ members =, :roles, :principal).order('roles.builtin, roles.position, users.firstname, users.lastname')
Benchmark.measure {, :roles, :principal).order('roles.builtin, roles.position, users.firstname, users.lastname').to_a }

#<Benchmark::Tms:0x00000008a427e0 @label="", @real=0.7370121359999757, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.6500000000000004, @total=0.6500000000000004>

Benchmark.measure {, :roles, :principal).to_a.sort }

#<Benchmark::Tms:0x0000000c68f450 @label="", @real=12.094179325009463, @cstime=0.0, @cutime=0.0, @stime=0.019999999999999962, @utime=12.029999999999998, @total=12.049999999999997>


#1 Updated by Go MAEDA about 1 year ago

Interesting. Reducing 12 sec to 0.6 sec is big improvement. How many members on the project?

Here is a diff made from the first post.

Index: app/views/projects/settings/_members.html.erb
--- app/views/projects/settings/_members.html.erb    (revision 15732)
+++ app/views/projects/settings/_members.html.erb    (working copy)
@@ -1,5 +1,5 @@
 <% roles = Role.find_all_givable
-   members =, :roles, :principal).to_a.sort %>
+   members =, :roles, :principal).order('roles.builtin, roles.position, users.firstname, users.lastname')

 <p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>

#2 Updated by Victor Campos about 1 year ago

6K members

#3 Updated by Toshi MARUYAMA about 1 year ago

I think SQL "users.firstname, users.lastname" order is not acceptable because AFAIK user sort is configurable.

Also available in: Atom PDF