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:
parent
df759bd310
commit
fb19703dba
1 changed files with 8 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue