mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 20:33:38 +08:00
FIX: User AvatarLookup
for looking up avatar details (#6508)
This allows plugins with their own avatar logic to work in the user summary sections.
This commit is contained in:
parent
f1ba981ae9
commit
f0af61da41
|
@ -60,19 +60,9 @@ class UserSummary
|
||||||
.order('COUNT(*) DESC')
|
.order('COUNT(*) DESC')
|
||||||
.limit(MAX_SUMMARY_RESULTS)
|
.limit(MAX_SUMMARY_RESULTS)
|
||||||
.pluck('acting_user_id, COUNT(*)')
|
.pluck('acting_user_id, COUNT(*)')
|
||||||
.each { |l| likers[l[0].to_s] = l[1] }
|
.each { |l| likers[l[0]] = l[1] }
|
||||||
|
|
||||||
User.where(id: likers.keys)
|
user_counts(likers)
|
||||||
.pluck(:id, :username, :name, :uploaded_avatar_id)
|
|
||||||
.map do |u|
|
|
||||||
UserWithCount.new(
|
|
||||||
id: u[0],
|
|
||||||
username: u[1],
|
|
||||||
name: u[2],
|
|
||||||
avatar_template: User.avatar_template(u[1], u[3]),
|
|
||||||
count: likers[u[0].to_s]
|
|
||||||
)
|
|
||||||
end.sort_by { |u| -u[:count] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def most_liked_users
|
def most_liked_users
|
||||||
|
@ -85,19 +75,9 @@ class UserSummary
|
||||||
.order('COUNT(*) DESC')
|
.order('COUNT(*) DESC')
|
||||||
.limit(MAX_SUMMARY_RESULTS)
|
.limit(MAX_SUMMARY_RESULTS)
|
||||||
.pluck('user_actions.user_id, COUNT(*)')
|
.pluck('user_actions.user_id, COUNT(*)')
|
||||||
.each { |l| liked_users[l[0].to_s] = l[1] }
|
.each { |l| liked_users[l[0]] = l[1] }
|
||||||
|
|
||||||
User.where(id: liked_users.keys)
|
user_counts(liked_users)
|
||||||
.pluck(:id, :username, :name, :uploaded_avatar_id)
|
|
||||||
.map do |u|
|
|
||||||
UserWithCount.new(
|
|
||||||
id: u[0],
|
|
||||||
username: u[1],
|
|
||||||
name: u[2],
|
|
||||||
avatar_template: User.avatar_template(u[1], u[3]),
|
|
||||||
count: liked_users[u[0].to_s]
|
|
||||||
)
|
|
||||||
end.sort_by { |u| -u[:count] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
REPLY_ACTIONS ||= [UserAction::RESPONSE, UserAction::QUOTE, UserAction::MENTION]
|
REPLY_ACTIONS ||= [UserAction::RESPONSE, UserAction::QUOTE, UserAction::MENTION]
|
||||||
|
@ -117,19 +97,9 @@ class UserSummary
|
||||||
.order('COUNT(*) DESC')
|
.order('COUNT(*) DESC')
|
||||||
.limit(MAX_SUMMARY_RESULTS)
|
.limit(MAX_SUMMARY_RESULTS)
|
||||||
.pluck('replies.user_id, COUNT(*)')
|
.pluck('replies.user_id, COUNT(*)')
|
||||||
.each { |r| replied_users[r[0].to_s] = r[1] }
|
.each { |r| replied_users[r[0]] = r[1] }
|
||||||
|
|
||||||
User.where(id: replied_users.keys)
|
user_counts(replied_users)
|
||||||
.pluck(:id, :username, :name, :uploaded_avatar_id)
|
|
||||||
.map do |u|
|
|
||||||
UserWithCount.new(
|
|
||||||
id: u[0],
|
|
||||||
username: u[1],
|
|
||||||
name: u[2],
|
|
||||||
avatar_template: User.avatar_template(u[1], u[3]),
|
|
||||||
count: replied_users[u[0].to_s]
|
|
||||||
)
|
|
||||||
end.sort_by { |u| -u[:count] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def badges
|
def badges
|
||||||
|
@ -215,4 +185,17 @@ class UserSummary
|
||||||
:time_read,
|
:time_read,
|
||||||
to: :user_stat
|
to: :user_stat
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def user_counts(user_hash)
|
||||||
|
user_ids = user_hash.keys
|
||||||
|
|
||||||
|
lookup = AvatarLookup.new(user_ids)
|
||||||
|
user_ids.map do |user_id|
|
||||||
|
UserWithCount.new(
|
||||||
|
lookup[user_id].attributes.merge(count: user_hash[user_id])
|
||||||
|
)
|
||||||
|
end.sort_by { |u| -u[:count] }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user