PERF: N+1 query on groups page.

This commit is contained in:
Guo Xiang Tan 2016-12-21 20:58:51 +08:00
parent 076a08d8e1
commit 5e75d5c1bf
4 changed files with 21 additions and 7 deletions

View File

@ -12,6 +12,15 @@ export default Ember.Component.extend({
return !!(this.currentUser) && allowMembershipRequests && aliasLevel === 99;
},
@computed("model.is_group_user", "model.id", "groupUserIds")
userIsGroupUser(isGroupUser, groupId, groupUserIds) {
if (isGroupUser) {
return isGroupUser;
} else {
return groupUserIds.includes(groupId);
}
},
actions: {
joinGroup() {
this.set('updatingMembership', true);

View File

@ -1,5 +1,5 @@
{{#if canJoinGroup}}
{{#if model.is_group_user}}
{{#if userIsGroupUser}}
{{d-button action="leaveGroup"
class="btn-danger group-index-leave"
icon="minus"
@ -13,7 +13,7 @@
disabled=updatingMembership}}
{{/if}}
{{else if canRequestMembership}}
{{#if model.is_group_user}}
{{#if userIsGroupUser}}
{{#if showMembershipStatus}}
{{d-button
class="btn-primary"

View File

@ -1,6 +1,5 @@
{{#d-section pageClass="groups"}}
<h1>{{i18n "groups.index.title"}}</h1>
{{#if groups}}
{{#load-more selector=".groups-table .groups-table-row" action="loadMore"}}
<div class='container'>
@ -47,7 +46,8 @@
<td>
{{#group-membership-button model=group
createNewMessageViaParams='createNewMessageViaParams'
showMembershipStatus=true}}
showMembershipStatus=true
groupUserIds=groups.extras.group_user_ids}}
{{d-button icon="ban"
label=(if group.automatic 'groups.automatic_group' 'groups.closed_group')

View File

@ -23,11 +23,16 @@ class GroupsController < ApplicationController
count = groups.count
groups = groups.offset(page * page_size).limit(page_size)
render json: {
groups: serialize_data(groups, GroupShowSerializer),
group_user_ids = GroupUser.where(group: groups, user: current_user).pluck(:group_id)
render_json_dump(
groups: serialize_data(groups, BasicGroupSerializer),
extras: {
group_user_ids: group_user_ids
},
total_rows_groups: count,
load_more_groups: groups_path(page: page + 1)
}
)
end
def show