Skip to content

Commit 4b5bf11

Browse files
Remove constant
1 parent 903922c commit 4b5bf11

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class FeedDatabaseManager(context: Context) {
2828
private val feedGroupTable = database.feedGroupDAO()
2929
private val streamTable = database.streamDAO()
3030

31-
companion object {
32-
/**
33-
* Only items that are newer than this will be saved.
34-
*/
35-
val FEED_OLDEST_ALLOWED_DATE: LocalDate = LocalDate.now().minusWeeks(13)
36-
}
37-
3831
fun groups() = feedGroupTable.getAll()
3932

4033
fun database() = database
@@ -79,11 +72,8 @@ class FeedDatabaseManager(context: Context) {
7972
return streamTable.exists(stream.serviceId, stream.url)
8073
}
8174

82-
fun upsertAll(
83-
subscriptionId: Long,
84-
items: List<StreamInfoItem>,
85-
oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE
86-
) {
75+
fun upsertAll(subscriptionId: Long, items: List<StreamInfoItem>) {
76+
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
8777
val zoneId = ZoneId.systemDefault()
8878
val itemsToInsert = items.filter {
8979
val uploadDate = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) }
@@ -107,7 +97,8 @@ class FeedDatabaseManager(context: Context) {
10797
)
10898
}
10999

110-
fun removeOrphansOrOlderStreams(oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE) {
100+
fun removeOrphansOrOlderStreams() {
101+
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
111102
val instant = oldestAllowedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()
112103
feedTable.unlinkStreamsOlderThan(instant)
113104
streamTable.deleteOrphans()

app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class FeedLoadManager(private val context: Context) {
254254
* Keep the feed and the stream tables small
255255
* to reduce loading times when trying to display the feed.
256256
* <br>
257-
* Remove streams from the feed which are older than [FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE].
257+
* Remove streams from the feed which are older than 13 weeks.
258258
* Remove streams from the database which are not linked / used by any table.
259259
*/
260260
private fun postProcessFeed() = Completable.fromRunnable {
@@ -321,13 +321,13 @@ class FeedLoadManager(private val context: Context) {
321321

322322
private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> {
323323
val zoneId = ZoneId.systemDefault()
324+
val oldestAllowedDate = LocalDate.now().minusWeeks(13)
324325
return list.filter {
325326
// Streams older than this date are automatically removed from the feed.
326327
// Therefore, streams which are not in the database,
327328
// but older than this date, are considered old.
328329
val date = it.uploadDate?.let { LocalDate.ofInstant(it.instant, zoneId) }
329-
!feedDatabaseManager.doesStreamExist(it) &&
330-
date != null && date > FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE
330+
!feedDatabaseManager.doesStreamExist(it) && date != null && date > oldestAllowedDate
331331
}
332332
}
333333
}

0 commit comments

Comments
 (0)