mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 05:40:52 +08:00
22 lines
486 B
Ruby
22 lines
486 B
Ruby
class AvatarLookup
|
|
|
|
def initialize(user_ids=[])
|
|
@user_ids = user_ids.tap(&:compact!).tap(&:uniq!).tap(&:flatten!)
|
|
end
|
|
|
|
# Lookup a user by id
|
|
def [](user_id)
|
|
users[user_id]
|
|
end
|
|
|
|
private
|
|
|
|
def users
|
|
@users ||= User.where(:id => @user_ids)
|
|
.select([:id, :email, :username, :use_uploaded_avatar, :uploaded_avatar_template, :uploaded_avatar_id])
|
|
.inject({}) do |hash, user|
|
|
hash.merge({user.id => user})
|
|
end
|
|
end
|
|
end
|