mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2025-10-03 09:49:21 +02:00
Remove constant
This commit is contained in:
parent
903922c2b0
commit
4b5bf11a04
2 changed files with 7 additions and 16 deletions
|
@ -28,13 +28,6 @@ class FeedDatabaseManager(context: Context) {
|
|||
private val feedGroupTable = database.feedGroupDAO()
|
||||
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 database() = database
|
||||
|
@ -79,11 +72,8 @@ class FeedDatabaseManager(context: Context) {
|
|||
return streamTable.exists(stream.serviceId, stream.url)
|
||||
}
|
||||
|
||||
fun upsertAll(
|
||||
subscriptionId: Long,
|
||||
items: List<StreamInfoItem>,
|
||||
oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE
|
||||
) {
|
||||
fun upsertAll(subscriptionId: Long, items: List<StreamInfoItem>) {
|
||||
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
|
||||
val zoneId = ZoneId.systemDefault()
|
||||
val itemsToInsert = items.filter {
|
||||
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()
|
||||
feedTable.unlinkStreamsOlderThan(instant)
|
||||
streamTable.deleteOrphans()
|
||||
|
|
|
@ -254,7 +254,7 @@ class FeedLoadManager(private val context: Context) {
|
|||
* Keep the feed and the stream tables small
|
||||
* to reduce loading times when trying to display the feed.
|
||||
* <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.
|
||||
*/
|
||||
private fun postProcessFeed() = Completable.fromRunnable {
|
||||
|
@ -321,13 +321,13 @@ class FeedLoadManager(private val context: Context) {
|
|||
|
||||
private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> {
|
||||
val zoneId = ZoneId.systemDefault()
|
||||
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
|
||||
return list.filter {
|
||||
// Streams older than this date are automatically removed from the feed.
|
||||
// Therefore, streams which are not in the database,
|
||||
// but older than this date, are considered old.
|
||||
val date = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) }
|
||||
!feedDatabaseManager.doesStreamExist(it) &&
|
||||
date != null && date > FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE
|
||||
!feedDatabaseManager.doesStreamExist(it) && date != null && date > oldestAllowedDate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue