
Issue: enhanced view request performance
Problem: There was so many queries occured to handle the request. Solution: Changed to reuse user collection on the view and prevented n+1 select by fetching.
@93cb0221539d176f3f391785ca5496958d5ddf61
--- app/models/ProjectUser.java
+++ app/models/ProjectUser.java
... | ... | @@ -20,9 +20,7 @@ |
20 | 20 |
*/ |
21 | 21 |
package models; |
22 | 22 |
|
23 |
-import java.util.LinkedHashMap; |
|
24 |
-import java.util.List; |
|
25 |
-import java.util.Map; |
|
23 |
+import java.util.*; |
|
26 | 24 |
|
27 | 25 |
import javax.persistence.Entity; |
28 | 26 |
import javax.persistence.Id; |
... | ... | @@ -93,7 +91,7 @@ |
93 | 91 |
} |
94 | 92 |
|
95 | 93 |
public static List<ProjectUser> findMemberListByProject(Long projectId) { |
96 |
- return find.fetch("user", "loginId").fetch("role", "name").where() |
|
94 |
+ return find.fetch("user").fetch("role", "name").where() |
|
97 | 95 |
.eq("project.id", projectId).ne("role.id", RoleType.SITEMANAGER.roleType()) |
98 | 96 |
.orderBy("user.name ASC") |
99 | 97 |
.findList(); |
--- app/models/User.java
+++ app/models/User.java
... | ... | @@ -338,31 +338,36 @@ |
338 | 338 |
} |
339 | 339 |
|
340 | 340 |
public static List<User> findUsersByProjectAndOrganization(Project project) { |
341 |
- Set<User> users = new HashSet<>(); |
|
342 |
- |
|
343 | 341 |
// member of this project. |
342 |
+ Set<Long> userIds = new HashSet<>(); |
|
343 |
+ |
|
344 | 344 |
List<ProjectUser> pus = project.members(); |
345 | 345 |
for(ProjectUser pu : pus) { |
346 |
- users.add(pu.user); |
|
346 |
+ userIds.add(pu.user.id); |
|
347 | 347 |
} |
348 | 348 |
|
349 | 349 |
// member of the group |
350 | 350 |
if(project.hasGroup()) { |
351 |
- List<OrganizationUser> ous = (project.isPublic() || project.isProtected()) ? project.organization.users : project.organization.getAdmins(); |
|
351 |
+ List<OrganizationUser> ous = null; |
|
352 |
+ if(project.isPrivate()) { |
|
353 |
+ ous = project.organization.getAdmins(); |
|
354 |
+ } else { |
|
355 |
+ ous = OrganizationUser.find.fetch("user") |
|
356 |
+ .where().eq("organization", project.organization).findList(); |
|
357 |
+ } |
|
358 |
+ |
|
352 | 359 |
for(OrganizationUser ou : ous) { |
353 |
- users.add(ou.user); |
|
360 |
+ userIds.add(ou.user.id); |
|
354 | 361 |
} |
355 | 362 |
} |
356 | 363 |
|
357 |
- // sorting |
|
358 |
- List<User> result = new ArrayList<>(users); |
|
359 |
- Collections.sort(result, USER_NAME_COMPARATOR); |
|
360 |
- |
|
361 | 364 |
if (UserApp.currentUser().isSiteManager()) { |
362 |
- result.add(UserApp.currentUser()); |
|
365 |
+ userIds.add(UserApp.currentUser().id); |
|
363 | 366 |
} |
364 | 367 |
|
365 |
- return result; |
|
368 |
+ List<User> users = find.where().in("id", userIds).orderBy().asc("name").findList(); |
|
369 |
+ |
|
370 |
+ return users; |
|
366 | 371 |
} |
367 | 372 |
|
368 | 373 |
@Transient |
--- app/views/issue/partial_assignee.scala.html
+++ app/views/issue/partial_assignee.scala.html
... | ... | @@ -22,11 +22,11 @@ |
22 | 22 |
|
23 | 23 |
@import utils.AccessControl._ |
24 | 24 |
|
25 |
-@makeOptionTagWithFlag(user:User, flag:String) = { |
|
25 |
+@makeOptionTagWithFlag(user:User, users:List[User], flag:String) = { |
|
26 | 26 |
<option value="@user.id" |
27 |
- data-avatar-url="@User.findByLoginId(user.loginId).avatarUrl" |
|
27 |
+ data-avatar-url="@user.avatarUrl" |
|
28 | 28 |
data-login-id="@user.loginId" |
29 |
- @if(!project.isAssignableUser(user)) { data-non-member="true" } |
|
29 |
+ @if(!users.contains(user)) { data-non-member="true" } |
|
30 | 30 |
@flag> |
31 | 31 |
@user.name |
32 | 32 |
</option> |
... | ... | @@ -46,15 +46,18 @@ |
46 | 46 |
} |
47 | 47 |
} |
48 | 48 |
} |
49 |
- @for(user <- project.getAssignableUsersAndAssignee(issue)){ |
|
50 |
- @if(issue != null && issue.assignee != null && issue.assignee.user.loginId == user.loginId) { |
|
51 |
- @makeOptionTagWithFlag(user, "selected") |
|
52 |
- } else { |
|
53 |
- @makeOptionTagWithFlag(user,"") |
|
49 |
+ @defining(project.getAssignableUsersAndAssignee(issue)) { users => |
|
50 |
+ @for(user <- users){ |
|
51 |
+ @if(issue != null && issue.assignee != null && issue.assignee.user.loginId == user.loginId) { |
|
52 |
+ @makeOptionTagWithFlag(user, users, "selected") |
|
53 |
+ } else { |
|
54 |
+ @makeOptionTagWithFlag(user, users, "") |
|
55 |
+ } |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ @if(issue != null && issue.assignee != null && issue.assignee.user.isSiteManager() && !UserApp.currentUser().isSiteManager()) { |
|
59 |
+ @makeOptionTagWithFlag(issue.assignee.user, users, "selected") |
|
54 | 60 |
} |
55 | 61 |
} |
56 | 62 |
|
57 |
- @if(issue != null && issue.assignee != null && issue.assignee.user.isSiteManager() && !UserApp.currentUser().isSiteManager()) { |
|
58 |
- @makeOptionTagWithFlag(issue.assignee.user, "selected") |
|
59 |
- } |
|
60 | 63 |
</select> |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?