mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
feat(LocalFeedRepository): don't fetch ChannelInfo if latest channel video is already known
This commit is contained in:
parent
c15352a33d
commit
c9e7af52f0
@ -14,6 +14,9 @@ interface SubscriptionsFeedDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(feedItems: List<SubscriptionsFeedItem>)
|
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")
|
@Query("DELETE FROM feedItem WHERE uploaded < :olderThan")
|
||||||
suspend fun cleanUpOlderThan(olderThan: Long)
|
suspend fun cleanUpOlderThan(olderThan: Long)
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.github.libretube.constants.PreferenceKeys
|
|||||||
import com.github.libretube.db.DatabaseHolder
|
import com.github.libretube.db.DatabaseHolder
|
||||||
import com.github.libretube.db.obj.SubscriptionsFeedItem
|
import com.github.libretube.db.obj.SubscriptionsFeedItem
|
||||||
import com.github.libretube.extensions.parallelMap
|
import com.github.libretube.extensions.parallelMap
|
||||||
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.helpers.NewPipeExtractorInstance
|
import com.github.libretube.helpers.NewPipeExtractorInstance
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
|
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
|
||||||
@ -73,10 +74,17 @@ class LocalFeedRepository : FeedRepository {
|
|||||||
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
|
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
|
||||||
val feedInfo = FeedInfo.getInfo(channelUrl)
|
val feedInfo = FeedInfo.getInfo(channelUrl)
|
||||||
|
|
||||||
val hasNewerUploads = feedInfo.relatedItems.any {
|
val mostRecentChannelVideo = feedInfo.relatedItems.maxBy {
|
||||||
(it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli()
|
it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
|
||||||
?: 0) > minimumDateMillis
|
} ?: 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()
|
if (!hasNewerUploads) return emptyList()
|
||||||
|
|
||||||
val channelInfo = ChannelInfo.getInfo(channelUrl)
|
val channelInfo = ChannelInfo.getInfo(channelUrl)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user