PERF: Only show members count on group page.

This commit is contained in:
Guo Xiang Tan 2016-12-02 16:27:47 +08:00
parent a93c59abbf
commit bc0a8142fe
5 changed files with 3 additions and 46 deletions

View File

@ -38,12 +38,9 @@ export default Ember.Controller.extend({
}; };
}, },
@observes('counts') @observes('model.user_count')
countsChanged() { _setMembersTabCount() {
const counts = this.get('counts'); this.get('tabs')[0].set('count', this.get('model.user_count'));
this.get('tabs').forEach(tab => {
tab.set('count', counts.get(tab.get('name')));
});
}, },
@observes('showing') @observes('showing')

View File

@ -166,10 +166,6 @@ Group.reopenClass({
}); });
}, },
findGroupCounts(name) {
return ajax("/groups/" + name + "/counts.json").then(result => Em.Object.create(result.counts));
},
find(name) { find(name) {
return ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group)); return ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group));
}, },

View File

@ -14,12 +14,6 @@ export default Discourse.Route.extend({
return { name: model.get('name').toLowerCase() }; return { name: model.get('name').toLowerCase() };
}, },
afterModel(model) {
return Group.findGroupCounts(model.get('name')).then(counts => {
this.set('counts', counts);
});
},
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ model, counts: this.get('counts') }); controller.setProperties({ model, counts: this.get('counts') });
} }

View File

@ -7,23 +7,6 @@ class GroupsController < ApplicationController
render_serialized(find_group(:id), GroupShowSerializer, root: 'basic_group') render_serialized(find_group(:id), GroupShowSerializer, root: 'basic_group')
end end
def counts
group = find_group(:group_id)
counts = {
posts: group.posts_for(guardian).count,
topics: group.posts_for(guardian).where(post_number: 1).count,
mentions: group.mentioned_posts_for(guardian).count,
members: group.users.count,
}
if guardian.can_see_group_messages?(group)
counts[:messages] = group.messages_for(guardian).where(post_number: 1).count
end
render json: { counts: counts }
end
def posts def posts
group = find_group(:group_id) group = find_group(:group_id)
posts = group.posts_for(guardian, params[:before_post_id]).limit(20) posts = group.posts_for(guardian, params[:before_post_id]).limit(20)

View File

@ -25,19 +25,6 @@ describe GroupsController do
end end
end end
describe "counts" do
it "returns counts if it can be seen" do
xhr :get, :counts, group_id: group.name
expect(response).to be_success
end
it "returns no counts if it can not be seen" do
group.update_columns(visible: false)
xhr :get, :counts, group_id: group.name
expect(response).not_to be_success
end
end
describe "posts" do describe "posts" do
it "ensures the group can be seen" do it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false) Guardian.any_instance.expects(:can_see?).with(group).returns(false)