mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 13:41:31 +08:00
PERF: Memoize allowed user fields more efficiently (#8968)
Previously we were caching by user_id, but the there are only two possible outcomes. Therefore we only need to cache two values. This removes another N+1 query when serializing multiple user cards.
This commit is contained in:
parent
2c7d32e783
commit
b37d2f09ba
|
@ -114,9 +114,13 @@ module UserGuardian
|
|||
|
||||
def allowed_user_field_ids(user)
|
||||
@allowed_user_field_ids ||= {}
|
||||
@allowed_user_field_ids[user.id] ||=
|
||||
|
||||
is_staff_or_is_me = is_staff? || is_me?(user)
|
||||
cache_key = is_staff_or_is_me ? :staff_or_me : :other
|
||||
|
||||
@allowed_user_field_ids[cache_key] ||=
|
||||
begin
|
||||
if is_staff? || is_me?(user)
|
||||
if is_staff_or_is_me
|
||||
UserField.pluck(:id)
|
||||
else
|
||||
UserField.where("show_on_profile OR show_on_user_card").pluck(:id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user