Skip to content

Commit 7c2c7ab

Browse files
committed
cache some repeated queries on the forums pages
1 parent eee3fe2 commit 7c2c7ab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/models/users/user.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def followed_by?(user)
6060
has_many :user_blockings, dependent: :destroy
6161
has_many :blocked_users, through: :user_blockings, source: :blocked_user
6262
def blocked_by_users
63-
User.where(id: UserBlocking.where(blocked_user_id: self.id).pluck(:user_id))
63+
@cached_blocked_by_users ||= User.where(id: UserBlocking.where(blocked_user_id: self.id).pluck(:user_id))
6464
end
6565
def blocked_by?(user)
6666
blocked_by_users.pluck(:id).include?(user.id)
@@ -206,7 +206,7 @@ def name
206206
end
207207

208208
def image_url(size=80)
209-
if avatar.attached? # manually-uploaded avatar
209+
@cached_user_image_url ||= if avatar.attached? # manually-uploaded avatar
210210
Rails.application.routes.url_helpers.rails_representation_url(avatar.variant(resize_to_limit: [size, size]).processed, only_path: true)
211211

212212
else # otherwise, grab the default from Gravatar for this email address
@@ -243,7 +243,7 @@ def active_promotions
243243
end
244244

245245
def active_promo_codes
246-
PageUnlockPromoCode.where(id: active_promotions.pluck(:page_unlock_promo_code_id))
246+
@cached_active_promo_codes ||= PageUnlockPromoCode.where(id: active_promotions.pluck(:page_unlock_promo_code_id))
247247
end
248248

249249
def initialize_stripe_customer

0 commit comments

Comments
 (0)