1
0
Fork 0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2025-10-03 09:49:21 +02:00

Remove constant

This commit is contained in:
Isira Seneviratne 2025-09-13 06:59:18 +05:30
parent 903922c2b0
commit 4b5bf11a04
2 changed files with 7 additions and 16 deletions

View file

@ -28,13 +28,6 @@ class FeedDatabaseManager(context: Context) {
private val feedGroupTable = database.feedGroupDAO() private val feedGroupTable = database.feedGroupDAO()
private val streamTable = database.streamDAO() private val streamTable = database.streamDAO()
companion object {
/**
* Only items that are newer than this will be saved.
*/
val FEED_OLDEST_ALLOWED_DATE: LocalDate = LocalDate.now().minusWeeks(13)
}
fun groups() = feedGroupTable.getAll() fun groups() = feedGroupTable.getAll()
fun database() = database fun database() = database
@ -79,11 +72,8 @@ class FeedDatabaseManager(context: Context) {
return streamTable.exists(stream.serviceId, stream.url) return streamTable.exists(stream.serviceId, stream.url)
} }
fun upsertAll( fun upsertAll(subscriptionId: Long, items: List<StreamInfoItem>) {
subscriptionId: Long, val oldestAllowedDate = LocalDate.now().minusWeeks(13)
items: List<StreamInfoItem>,
oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE
) {
val zoneId = ZoneId.systemDefault() val zoneId = ZoneId.systemDefault()
val itemsToInsert = items.filter { val itemsToInsert = items.filter {
val uploadDate = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) } val uploadDate = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) }
@ -107,7 +97,8 @@ class FeedDatabaseManager(context: Context) {
) )
} }
fun removeOrphansOrOlderStreams(oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE) { fun removeOrphansOrOlderStreams() {
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
val instant = oldestAllowedDate.atStartOfDay(ZoneId.systemDefault()).toInstant() val instant = oldestAllowedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()
feedTable.unlinkStreamsOlderThan(instant) feedTable.unlinkStreamsOlderThan(instant)
streamTable.deleteOrphans() streamTable.deleteOrphans()

View file

@ -254,7 +254,7 @@ class FeedLoadManager(private val context: Context) {
* Keep the feed and the stream tables small * Keep the feed and the stream tables small
* to reduce loading times when trying to display the feed. * to reduce loading times when trying to display the feed.
* <br> * <br>
* Remove streams from the feed which are older than [FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE]. * Remove streams from the feed which are older than 13 weeks.
* Remove streams from the database which are not linked / used by any table. * Remove streams from the database which are not linked / used by any table.
*/ */
private fun postProcessFeed() = Completable.fromRunnable { private fun postProcessFeed() = Completable.fromRunnable {
@ -321,13 +321,13 @@ class FeedLoadManager(private val context: Context) {
private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> { private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> {
val zoneId = ZoneId.systemDefault() val zoneId = ZoneId.systemDefault()
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
return list.filter { return list.filter {
// Streams older than this date are automatically removed from the feed. // Streams older than this date are automatically removed from the feed.
// Therefore, streams which are not in the database, // Therefore, streams which are not in the database,
// but older than this date, are considered old. // but older than this date, are considered old.
val date = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) } val date = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) }
!feedDatabaseManager.doesStreamExist(it) && !feedDatabaseManager.doesStreamExist(it) && date != null && date > oldestAllowedDate
date != null && date > FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE
} }
} }
} }