fix: auto-delete feed videos when unsubscribing from channel when using local feed extraction

This commit is contained in:
Bnyro 2025-01-11 11:41:13 +01:00
parent f38f0ed706
commit 5e6a42c629
2 changed files with 10 additions and 6 deletions

View File

@ -17,6 +17,9 @@ interface SubscriptionsFeedDao {
@Query("DELETE FROM feedItem WHERE uploaded < :olderThan")
suspend fun cleanUpOlderThan(olderThan: Long)
@Query("DELETE FROM feedItem WHERE uploaderUrl NOT IN (:channelUrls)")
suspend fun deleteAllExcept(channelUrls: List<String>)
@Query("DELETE FROM feedItem")
suspend fun deleteAll()
}

View File

@ -23,6 +23,11 @@ class LocalFeedRepository : FeedRepository {
override suspend fun getFeed(forceRefresh: Boolean): List<StreamItem> {
val nowMillis = Instant.now().toEpochMilli()
val minimumDateMillis = nowMillis - Duration.ofDays(MAX_FEED_AGE_DAYS).toMillis()
val channelIds = SubscriptionHelper.getSubscriptionChannelIds()
// remove videos from channels that are no longer subscribed
DatabaseHolder.Database.feedDao().deleteAllExcept(channelIds.map { id -> "/channel/${id}" })
if (!forceRefresh) {
val feed = DatabaseHolder.Database.feedDao().getAll()
@ -37,18 +42,14 @@ class LocalFeedRepository : FeedRepository {
}
}
val minimumDateMillis = nowMillis - Duration.ofDays(MAX_FEED_AGE_DAYS).toMillis()
DatabaseHolder.Database.feedDao().cleanUpOlderThan(minimumDateMillis)
refreshFeed(minimumDateMillis)
refreshFeed(channelIds, minimumDateMillis)
PreferenceHelper.putLong(PreferenceKeys.LAST_FEED_REFRESH_TIMESTAMP_MILLIS, nowMillis)
return DatabaseHolder.Database.feedDao().getAll().map(SubscriptionsFeedItem::toStreamItem)
}
private suspend fun refreshFeed(minimumDateMillis: Long) {
val channelIds = SubscriptionHelper.getSubscriptionChannelIds()
private suspend fun refreshFeed(channelIds: List<String>, minimumDateMillis: Long) {
for (channelIdChunk in channelIds.chunked(CHUNK_SIZE)) {
val collectedFeedItems = channelIdChunk.parallelMap { channelId ->
try {