forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavatar_lookup.rb
More file actions
38 lines (32 loc) · 792 Bytes
/
Copy pathavatar_lookup.rb
File metadata and controls
38 lines (32 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 self.lookup_columns
@lookup_columns ||= [:id,
:email,
:username,
:use_uploaded_avatar,
:uploaded_avatar_template,
:uploaded_avatar_id]
end
def users
@users ||= user_lookup_hash
end
def user_lookup_hash
# adding tap here is a personal taste thing
hash = {}
User
.where(:id => @user_ids)
.select(AvatarLookup.lookup_columns)
.each{|user|
hash[user.id] = user
}
hash
end
end