Skip to content

Commit

Permalink
Fix missing episodes with unfollowed podcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
geekygecko committed Feb 5, 2025
1 parent 53e9252 commit 2c2dd99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import java.util.Calendar
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -224,25 +224,35 @@ class PodcastManagerImpl @Inject constructor(

// we don't delete podcasts added to the phone in the last week. This is to prevent stuff you just leave open in discover from being removed
val addedDate = podcast.addedDate
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, -7)
val oneWeekAgo = calendar.time
if (addedDate != null && addedDate > oneWeekAgo) {
val oneWeekAgoMs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)
if (addedDate != null && addedDate.time > oneWeekAgoMs) {
return false
}

// podcasts can be deleted if all of the episodes are haven't been interacted with
val episodes = episodeManager.findEpisodesByPodcastOrderedBlocking(podcast)
var podcastHasChangedEpisodes = false
var latestPlaybackInteraction = 0L
val deleteEpisodes = mutableListOf<PodcastEpisode>()
for (episode in episodes) {
// find the latest playback interaction
episode.lastPlaybackInteraction?.let { interaction ->
if (interaction > latestPlaybackInteraction) {
latestPlaybackInteraction = interaction
}
}
if (episodeManager.userHasInteractedWithEpisode(episode, playbackManager)) {
podcastHasChangedEpisodes = true
continue
}
// bulk delete or it takes 10 seconds on a large podcast
deleteEpisodes.add(episode)
}
// don't remove episodes or the podcast if the latest playback interaction was less than a month ago,
val oneMonthAgoMs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30)
if (latestPlaybackInteraction > oneMonthAgoMs) {
return false
}
if (deleteEpisodes.isNotEmpty()) {
episodeManager.deleteEpisodesWithoutSyncBlocking(deleteEpisodes, playbackManager)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class PodcastRefresherImpl @Inject constructor(
override suspend fun refreshPodcast(existingPodcast: Podcast, playbackManager: PlaybackManager) {
try {
val podcastResponse = cacheServiceManager.getPodcastResponse(existingPodcast.uuid)
if (podcastResponse.wasCached() || podcastResponse.notModified()) {
// podcasts that aren't subscribed can have episodes removed, so always refresh them
if (existingPodcast.isSubscribed && (podcastResponse.wasCached() || podcastResponse.notModified())) {
LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Refreshing podcast ${existingPodcast.uuid} not required as cached")
return
}
Expand Down

0 comments on commit 2c2dd99

Please sign in to comment.