Ensuring we fetch latest podcasts by pubDate (#16319)
* Ensuring we fetch latest podcasts by pubDate Prior to this commit, we fetched the podcasts that were the first(:limit) XML `item` nodes in the RSS feed. Some folks might choose to list those in descending pubDate order, while others list in ascending pubDate order. Closes #3580 * Bump for travis
This commit is contained in:
parent
60639bcb71
commit
fa8b55117d
1 changed files with 12 additions and 1 deletions
|
|
@ -7,6 +7,10 @@ module Podcasts
|
|||
@podcast = podcast
|
||||
end
|
||||
|
||||
# @note While the limit might look generous, the callers are passing the value (which they
|
||||
# themselves receive elsewhere). In one case, the :limit is 5
|
||||
#
|
||||
# @see Podcasts::EnqueueGetEpisodesWorker
|
||||
def get_episodes(limit: 100, force_update: false)
|
||||
# increased the redirect limit from 5 (default) to 7 to be able to handle such urls
|
||||
rss = HTTParty.get(podcast.feed_url, limit: 7).body.to_s
|
||||
|
|
@ -15,7 +19,14 @@ module Podcasts
|
|||
set_unreachable(status: :unparsable, force_update: force_update) && return unless feed
|
||||
|
||||
get_episode = Podcasts::GetEpisode.new(podcast)
|
||||
feed.items.first(limit).each do |item|
|
||||
# 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|
|
||||
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