diff --git a/app/models/party.rb b/app/models/party.rb index 31b1b7b..1a949c1 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -120,9 +120,6 @@ class Party < ApplicationRecord PREVIEW_EXPIRY = 30.days MAX_RETRY_ATTEMPTS = 3 - def is_favorited(user) - user.favorite_parties.include? self if user - end after_commit :schedule_preview_generation, if: :should_generate_preview? def is_remix @@ -149,6 +146,14 @@ class Party < ApplicationRecord visibility == 3 end + def is_favorited(user) + return false unless user + + Rails.cache.fetch("party_#{id}_favorited_by_#{user.id}", expires_in: 1.hour) do + user.favorite_parties.include?(self) + end + end + def ready_for_preview? return false if weapons_count < 1 # At least 1 weapon return false if characters_count < 1 # At least 1 character