Skip to content

Commit

Permalink
Hotfix: Only run invalidations on attached images
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Oct 17, 2024
1 parent 9509415 commit f10af12
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/user_avatar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class UserAvatar < ApplicationRecord

default_scope { with_attached_public_image }

delegate :attached?, to: :image

enum :status, {
pending: 'pending',
approved: 'approved',
Expand Down Expand Up @@ -76,7 +78,7 @@ def thumbnail_url

def using_cdn?
# Approved avatars are actively being used and should therefor be served by our CDN
self.approved?
self.approved? && self.attached?
end

def filename
Expand Down Expand Up @@ -189,7 +191,7 @@ def move_image_if_approved
end

after_save :invalidate_thumbnail_if_approved,
if: [:active_storage?, :approved?],
if: [:active_storage?, :approved?, :attached?],
unless: :destroyed?

def invalidate_thumbnail_if_approved
Expand Down

0 comments on commit f10af12

Please sign in to comment.