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

Copy link
Member

@cavis cavis Jan 24, 2025

Choose a reason for hiding this comment

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

Remembering now - nil segment counts either come in from RSS imports (items with no media), or API users.

We were keeping these nil for API users. So when they PUT an update, they don't need to send both media: [...three urls...] and a matching segment_count: 3.

We could change media= to also set the segment count? That setter is used in 3 places:

  1. The API (we'd just have to decide segment_count related validations can't be used by API users, which is maybe fine)
  2. The EpisodeRssImport, but it's immediately setting the segment count after that. So changing would be fine.
  3. Uncut.slice_contents, which i can't imagine the segmentation not matching the segment count anyways right? Or we could build contents in a different way there, which would maybe be better.

Or we don't force these to be set here. (The UI handles nils already).

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.

Copy link
Member

Choose a reason for hiding this comment

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

Just checked prod, and I see 1829 invalid EpisodeImages. But 0 ITunesImages. Since this isn't a problem there, probably don't need the validation in both models.

end

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