mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
PERF: don't run stats query in user card
This commit is contained in:
parent
8c7cce1bfc
commit
130dbf7358
|
@ -71,7 +71,7 @@ export default ObjectController.extend({
|
|||
this.setProperties({ user: null, userLoading: username, cardTarget: target });
|
||||
|
||||
var self = this;
|
||||
Discourse.User.findByUsername(username).then(function (user) {
|
||||
Discourse.User.findByUsername(username, {stats: false}).then(function (user) {
|
||||
user = Discourse.User.create(user);
|
||||
self.setProperties({ user: user, avatar: user, visible: true});
|
||||
self.appEvents.trigger('usercard:shown');
|
||||
|
|
|
@ -292,11 +292,11 @@ Discourse.User = Discourse.Model.extend({
|
|||
return this.get('stats').rejectProperty('isPM');
|
||||
}.property('stats.@each.isPM'),
|
||||
|
||||
findDetails: function() {
|
||||
findDetails: function(options) {
|
||||
var user = this;
|
||||
|
||||
return PreloadStore.getAndRemove("user_" + user.get('username'), function() {
|
||||
return Discourse.ajax("/users/" + user.get('username') + '.json');
|
||||
return Discourse.ajax("/users/" + user.get('username') + '.json', {data: options});
|
||||
}).then(function (json) {
|
||||
|
||||
if (!Em.isEmpty(json.user.stats)) {
|
||||
|
@ -468,9 +468,9 @@ Discourse.User.reopenClass(Discourse.Singleton, {
|
|||
@method findByUsername
|
||||
@returns {Promise} a promise that resolves to a `Discourse.User`
|
||||
**/
|
||||
findByUsername: function(username) {
|
||||
findByUsername: function(username, options) {
|
||||
var user = Discourse.User.create({username: username});
|
||||
return user.findDetails();
|
||||
return user.findDetails(options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,6 +28,9 @@ class UsersController < ApplicationController
|
|||
def show
|
||||
@user = fetch_user_from_params
|
||||
user_serializer = UserSerializer.new(@user, scope: guardian, root: 'user')
|
||||
if params[:stats].to_s == "false"
|
||||
user_serializer.omit_stats = true
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@restrict_fields = guardian.restrict_user_fields?(@user)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class UserSerializer < BasicUserSerializer
|
||||
|
||||
attr_accessor :omit_stats
|
||||
|
||||
def self.staff_attributes(*attrs)
|
||||
attributes(*attrs)
|
||||
attrs.each do |attr|
|
||||
|
@ -171,6 +173,10 @@ class UserSerializer < BasicUserSerializer
|
|||
scope.can_edit_name?(object)
|
||||
end
|
||||
|
||||
def include_stats?
|
||||
!omit_stats == true
|
||||
end
|
||||
|
||||
def stats
|
||||
UserAction.stats(object.id, scope)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user