Merge pull request #6951 from Bnyro/master

feat(LocalFeedRepository): don't fetch ChannelInfo if latest channel video is already known
This commit is contained in:
Bnyro 2025-01-13 17:05:28 +01:00 committed by GitHub
commit 226c80162a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View File

@ -14,6 +14,9 @@ interface SubscriptionsFeedDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(feedItems: List<SubscriptionsFeedItem>)
@Query("SELECT EXISTS (SELECT * FROM feedItem WHERE videoId = :videoId)")
suspend fun contains(videoId: String): Boolean
@Query("DELETE FROM feedItem WHERE uploaded < :olderThan")
suspend fun cleanUpOlderThan(olderThan: Long)

View File

@ -9,6 +9,7 @@ import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SubscriptionsFeedItem
import com.github.libretube.enums.ContentFilter
import com.github.libretube.extensions.parallelMap
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.NewPipeExtractorInstance
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
@ -80,10 +81,17 @@ class LocalFeedRepository : FeedRepository {
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
val feedInfo = FeedInfo.getInfo(channelUrl)
val hasNewerUploads = feedInfo.relatedItems.any {
(it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli()
?: 0) > minimumDateMillis
}
val mostRecentChannelVideo = feedInfo.relatedItems.maxBy {
it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
} ?: return emptyList()
// check if the channel has at least one video whose upload time is newer than the maximum
// feed ago and which is not yet stored in the database
val mostRecentUploadTime =
mostRecentChannelVideo.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
val hasNewerUploads =
mostRecentUploadTime > minimumDateMillis && !DatabaseHolder.Database.feedDao()
.contains(mostRecentChannelVideo.url.replace(YOUTUBE_FRONTEND_URL, "").toID())
if (!hasNewerUploads) return emptyList()
val channelInfo = ChannelInfo.getInfo(channelUrl)