Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore images unless changed, default segment count when nil #1170

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/models/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def image=(file)

def set_defaults
guid
self.segment_count ||= 1 if new_record? && strict_validations
if new_record? && strict_validations
self.segment_count ||= 1
elsif segment_count.blank? && contents.any?
self.segment_count = contents.map(&:position).max || contents.size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a bit more nervous. There's already logic in the episode media to set this field, and to handle nil segment_counts (I've definitely seen those in the wild).

Was this also an issue with the ep referenced in the ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, as I recall it had a 0 segment count, even though it had audio

end
end

def guid
Expand Down
8 changes: 6 additions & 2 deletions app/models/episode_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ class EpisodeImage < ApplicationRecord

belongs_to :episode, touch: true, optional: true

validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :status_complete?
validates :width, comparison: {equal_to: :height}, if: :status_complete?
validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :should_validate?
validates :width, comparison: {equal_to: :height}, if: :should_validate?

def should_validate?
status_complete? && (height_changed? || width_changed?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any case for moving this to the shared ImageFile? ITunesImage has similar validations, and there's a :format validation as well.

I see 1829 invalid episode images in prod ... as recently created as Feb 2023. Bit surprised by that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image format on this one wasn't an issue, just the dimensions; probably we enforced a more lax value in the past.

end

def destination_path
"#{episode.path}/#{image_path}"
Expand Down
Loading