Actions
Patch #23378
closedSpeedup Project Settings with many members
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Performance
Target version:
-
Start date:
Due date:
% Done:
0%
Estimated time:
Description
Hi,
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 = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort + members = @project.memberships.active.includes(:member_roles, :roles, :principal).order('roles.builtin, roles.position, users.firstname, users.lastname')
Benchmark.measure { project.memberships.active.includes(:member_roles, :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 { project.memberships.active.includes(:member_roles, :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>
Updated by Go MAEDA over 8 years 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 = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort %>
+ members = @project.memberships.active.includes(:member_roles, :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>
Updated by Toshi MARUYAMA over 8 years ago
I think SQL "users.firstname, users.lastname" order is not acceptable because AFAIK user sort is configurable.
source:tags/3.3.0/app/models/user.rb#L24
Actions