Add cache to is_favorited(user)
This commit is contained in:
parent
dc24f4e600
commit
cca4427a75
1 changed files with 8 additions and 3 deletions
|
|
@ -120,9 +120,6 @@ class Party < ApplicationRecord
|
||||||
PREVIEW_EXPIRY = 30.days
|
PREVIEW_EXPIRY = 30.days
|
||||||
MAX_RETRY_ATTEMPTS = 3
|
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?
|
after_commit :schedule_preview_generation, if: :should_generate_preview?
|
||||||
|
|
||||||
def is_remix
|
def is_remix
|
||||||
|
|
@ -149,6 +146,14 @@ class Party < ApplicationRecord
|
||||||
visibility == 3
|
visibility == 3
|
||||||
end
|
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?
|
def ready_for_preview?
|
||||||
return false if weapons_count < 1 # At least 1 weapon
|
return false if weapons_count < 1 # At least 1 weapon
|
||||||
return false if characters_count < 1 # At least 1 character
|
return false if characters_count < 1 # At least 1 character
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue