From c541b692efbab043a9454a0bfbdef4c40d19b09a Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Tue, 31 Oct 2023 16:42:17 -0500 Subject: [PATCH] Run retrieveLatestChapters once for the latest episode in parser --- src/services/parser.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/services/parser.ts b/src/services/parser.ts index bccc53cc..18650d49 100644 --- a/src/services/parser.ts +++ b/src/services/parser.ts @@ -35,7 +35,8 @@ import { import { getEpisodeByPodcastIdAndGuid, getEpisodesWithLiveItemsWithMatchingGuids, - getEpisodesWithLiveItemsWithoutMatchingGuids + getEpisodesWithLiveItemsWithoutMatchingGuids, + retrieveLatestChapters } from '~/controllers/episode' import { getLiveItemByGuid } from '~/controllers/liveItem' import { PhasePendingChat } from 'podcast-partytime/dist/parser/phase/phase-pending' @@ -522,15 +523,15 @@ export const parseFeedUrl = async (feedUrl, forceReparsing = false, cacheBust = await feedUrlRepo.update(feedUrl.id, cleanedFeedUrl) logPerformance('feedUrlRepo.update', _logEnd) + // Retrieve the episode to make sure we have the episode.id + const latestEpisodeWithId = await getEpisodeByPodcastIdAndGuid(podcast.id, latestEpisodeGuid) + if (shouldSendNewEpisodeNotification) { logPerformance('sendNewEpisodeDetectedNotification', _logStart) const podcastShrunkImageUrl = podcast.shrunkImageUrl const podcastFullImageUrl = podcast.imageUrl const episodeFullImageUrl = latestEpisodeImageUrl - // Retrieve the episode to make sure we have the episode.id - const latestEpisodeWithId = await getEpisodeByPodcastIdAndGuid(podcast.id, latestEpisodeGuid) - if (latestEpisodeWithId?.id) { await sendNewEpisodeDetectedNotification({ podcastId: podcast.id, @@ -596,6 +597,15 @@ export const parseFeedUrl = async (feedUrl, forceReparsing = false, cacheBust = } } logPerformance('newEpisodes updateSoundBites', _logEnd) + + logPerformance('retrieveLatestChapters', _logStart) + // Run retrieveLatestChapters only for the latest episode to make sure + // chapters are pre-populated in our database. Otherwise the first person + // who plays the episode will not see chapters. + if (latestEpisodeWithId?.id) { + await retrieveLatestChapters(latestEpisodeWithId.id) + } + logPerformance('retrieveLatestChapters', _logEnd) } catch (error) { throw error } finally {