Skip to content

Commit

Permalink
Run retrieveLatestChapters once for the latest episode in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchdowney committed Oct 31, 2023
1 parent 1facd1a commit c541b69
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c541b69

Please sign in to comment.