Allow nil pubDate in Podcast sorting (#16349)
* Allow nil pubDate in Podcast sorting * Choose a shorter syntax * Typo
This commit is contained in:
parent
0132ef67ee
commit
0559a808c4
1 changed files with 3 additions and 8 deletions
|
|
@ -19,14 +19,9 @@ module Podcasts
|
|||
set_unreachable(status: :unparsable, force_update: force_update) && return unless feed
|
||||
|
||||
get_episode = Podcasts::GetEpisode.new(podcast)
|
||||
# NOTE: `sort { |a, b| b.pubDate <=> a.pubDate }` is logically equivalent to
|
||||
# `sort_by(&:pubDate).reverse` but only iterates once through the array.
|
||||
#
|
||||
# The sort ensures that we're fetching the most recently published episodes. This addresses
|
||||
# https://github.com/forem/forem/issues/3580, in which some RSS feeds list their episodes in
|
||||
# earliest to latest, whereas others list latest to earliest. We assume that we're wanting to
|
||||
# track the latest.
|
||||
feed.items.sort { |a, b| b.pubDate <=> a.pubDate }.first(limit).each do |item|
|
||||
|
||||
# Sort by published date in descending order
|
||||
feed.items.sort_by { |i| -i.pubDate.to_i }.first(limit).each do |item|
|
||||
get_episode.call(item: item, force_update: force_update)
|
||||
end
|
||||
podcast.update_columns(reachable: true, status_notice: "")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue