From fb19703dbaf4cd6230aa7a0c11e7e1fce443983f Mon Sep 17 00:00:00 2001 From: Mac Siri Date: Wed, 10 Jun 2020 10:39:36 -0400 Subject: [PATCH] Update UserDecorator not to cache AR Object (#8378) * Update UserDecorator not to cache AR Object * Change cache name * Change cache name to reduce invalidation frequency --- app/decorators/user_decorator.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index eedbb50b2..07a78fb39 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -19,16 +19,15 @@ class UserDecorator < ApplicationDecorator ].freeze def cached_followed_tags - Rails.cache.fetch("user-#{id}-#{updated_at}/followed_tags_11-30", expires_in: 20.hours) do - follows = Follow.follower_tag(id).pluck(:followable_id, :points) - follows_map = follows.to_h - - tags = Tag.where(id: follows_map.keys).order(hotness_score: :desc) - tags.each do |tag| - tag.points = follows_map[tag.id] - end - tags + follows_map = Rails.cache.fetch("user-#{id}-#{last_followed_at&.rfc3339}/followed_tags", expires_in: 20.hours) do + Follow.follower_tag(id).pluck(:followable_id, :points).to_h end + + tags = Tag.where(id: follows_map.keys).order(hotness_score: :desc) + tags.each do |tag| + tag.points = follows_map[tag.id] + end + tags end def darker_color(adjustment = 0.88)