From 4b5bf11a04b2f2de59f0a1ae64a6161f44f1e20a Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 13 Sep 2025 06:59:18 +0530 Subject: [PATCH] Remove constant --- .../newpipe/local/feed/FeedDatabaseManager.kt | 17 ++++------------- .../local/feed/service/FeedLoadManager.kt | 6 +++--- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt index 60fb5b09c..aae713f84 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt @@ -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, - oldestAllowedDate: LocalDate = FEED_OLDEST_ALLOWED_DATE - ) { + fun upsertAll(subscriptionId: Long, items: List) { + 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() diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt index 3aff7d87d..63984acd4 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt @@ -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. *
- * 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): List { 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 } } }