mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #4569 from tgxworld/fix_n+1_queries
PERF: Fix N+1 queries when loading groups.
This commit is contained in:
@@ -2,7 +2,7 @@ import NotificationsButton from 'discourse/components/notifications-button';
|
||||
|
||||
export default NotificationsButton.extend({
|
||||
classNames: ['notification-options', 'group-notification-menu'],
|
||||
notificationLevel: Em.computed.alias('group.notification_level'),
|
||||
notificationLevel: Em.computed.alias('group.group_user.notification_level'),
|
||||
i18nPrefix: 'groups.notifications',
|
||||
|
||||
clicked(id) {
|
||||
|
||||
@@ -41,8 +41,16 @@ export default Ember.Controller.extend({
|
||||
});
|
||||
},
|
||||
|
||||
@computed('model.is_member')
|
||||
getTabs(isMember) {
|
||||
return this.get('tabs').filter(t => isMember || !t.get('requiresMembership'));
|
||||
@computed('model.is_group_user')
|
||||
getTabs(isGroupUser) {
|
||||
return this.get('tabs').filter(t => {
|
||||
let isMember = false;
|
||||
|
||||
if (this.currentUser) {
|
||||
isMember = this.currentUser.admin || isGroupUser;
|
||||
}
|
||||
|
||||
return isMember || !t.get('requiresMembership');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ const Group = Discourse.Model.extend({
|
||||
},
|
||||
|
||||
setNotification(notification_level) {
|
||||
this.set("notification_level", notification_level);
|
||||
this.set("group_user.notification_level", notification_level);
|
||||
return ajax(`/groups/${this.get("name")}/notifications`, {
|
||||
data: { notification_level },
|
||||
type: "POST"
|
||||
@@ -181,7 +181,11 @@ Group.reopenClass({
|
||||
offset: offset || 0
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
mentionable(name) {
|
||||
return ajax(`/groups/${name}/mentionable`, { data: { name } });
|
||||
},
|
||||
});
|
||||
|
||||
export default Group;
|
||||
|
||||
@@ -341,7 +341,15 @@ const User = RestModel.extend({
|
||||
}
|
||||
|
||||
if (!Em.isEmpty(json.user.groups)) {
|
||||
json.user.groups = json.user.groups.map(g => Group.create(g));
|
||||
const groups = [];
|
||||
|
||||
for(let i = 0; i < json.user.groups.length; i++) {
|
||||
const group = Group.create(json.user.groups[i]);
|
||||
group.group_user = json.user.group_users[i];
|
||||
groups.push(group);
|
||||
}
|
||||
|
||||
json.user.groups = groups;
|
||||
}
|
||||
|
||||
if (json.user.invited_by) {
|
||||
|
||||
@@ -21,11 +21,11 @@ export default Discourse.Route.extend({
|
||||
});
|
||||
} else if (params.groupname) {
|
||||
// send a message to a group
|
||||
Group.find(params.groupname).then(group => {
|
||||
if (group.mentionable) {
|
||||
Ember.run.next(() => e.send("createNewMessageViaParams", group.name, params.title, params.body));
|
||||
Group.mentionable(params.groupname).then(result => {
|
||||
if (result.mentionable) {
|
||||
Ember.run.next(() => e.send("createNewMessageViaParams", params.groupname, params.title, params.body));
|
||||
} else {
|
||||
bootbox.alert(I18n.t("composer.cant_send_pm", { username: group.name }));
|
||||
bootbox.alert(I18n.t("composer.cant_send_pm", { username: params.groupname }));
|
||||
}
|
||||
}).catch(function() {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
|
||||
Reference in New Issue
Block a user