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

Conversation

kookster
Copy link
Member

fix issues with update errors for older Mortified issues -
https://prx.zendesk.com/agent/tickets/204696

@kookster kookster requested a review from cavis December 21, 2024 23:35
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.

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).

@cavis
Copy link
Member

cavis commented Jan 23, 2025

I'm also wondering if this relates to #1040. Where an import creates an invalid image, but the UI wasn't telling me it was invalid.

@cavis
Copy link
Member

cavis commented Jan 23, 2025

Retesting some things - I'm not sure this would ever be an issue with recent data? (Since the introduction of `image.status == "invalid"). These days, the porter callbacks would set the image.status to invalid, so the validation wouldn't run in the first place.

Copy link
Member

@cavis cavis left a comment

Choose a reason for hiding this comment

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

Need to figure out what to do about the segment_count. But otherwise this looks good!

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

@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).

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.

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.

@kookster
Copy link
Member Author

looks like this might cause problems with API calls (spoolr) that are not setting segments - do not merge quite yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants