Move caching of reaction to rediscache (#4819)

This commit is contained in:
jeffin sam 2019-11-16 00:08:46 +05:30 committed by Mac Siri
parent 7cc5ef5e40
commit e92b005d02

View file

@ -59,8 +59,8 @@ class Reaction < ApplicationRecord
def cached_any_reactions_for?(reactable, user, category)
class_name = reactable.class.name == "ArticleDecorator" ? "Article" : reactable.class.name
cache_name = "any_reactions_for-#{class_name}-#{reactable.id}-#{user.updated_at}-#{category}"
Rails.cache.fetch(cache_name, expires_in: 24.hours) do
cache_name = "any_reactions_for-#{class_name}-#{reactable.id}-#{user.updated_at&.rfc3339}-#{category}"
RedisRailsCache.fetch(cache_name, expires_in: 24.hours) do
Reaction.where(reactable_id: reactable.id, reactable_type: class_name, user: user, category: category).any?
end
end