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
This commit is contained in:
Mac Siri 2020-06-10 10:39:36 -04:00 committed by GitHub
parent df759bd310
commit fb19703dba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)