diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-09-14 11:46:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-14 11:46:39 +0200 |
commit | 6b189a0d472a523caf6de313b13eea23b466a278 (patch) | |
tree | 54a2a141314342982813c0e225d2e8ffa6f56814 | |
parent | 2a1b537d13f018d4a08e14076700ff297c946bff (diff) | |
download | AntennaPod-6b189a0d472a523caf6de313b13eea23b466a278.zip |
Delete non-subscribed, non-interacted feeds earlier (#7399)
2 files changed, 28 insertions, 3 deletions
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java index 31d4c4d7f..fa27e6e5b 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java @@ -10,7 +10,8 @@ import java.util.List; public class NonSubscribedFeedsCleaner { private static final String TAG = "NonSubscrFeedsCleaner"; - private static final long TIME_TO_KEEP = 1000L * 3600 * 24 * 30; // 30 days + private static final long TIME_TO_KEEP_UNTOUCHED = 1000L * 3600 * 24; // 1 day + private static final long TIME_TO_KEEP_PLAYED = 1000L * 3600 * 24 * 30; // 30 days public static void deleteOldNonSubscribedFeeds(Context context) { List<Feed> feeds = DBReader.getFeedList(); @@ -35,6 +36,10 @@ public class NonSubscribedFeedsCleaner { } else if (feed.hasEpisodeInApp()) { return false; } - return feed.getLastRefreshAttempt() < System.currentTimeMillis() - TIME_TO_KEEP; + long timeSinceLastRefresh = System.currentTimeMillis() - feed.getLastRefreshAttempt(); + if (!feed.hasInteractedWithEpisode()) { + return timeSinceLastRefresh > TIME_TO_KEEP_UNTOUCHED; + } + return timeSinceLastRefresh > TIME_TO_KEEP_PLAYED; } } diff --git a/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java b/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java index 76bbfddc1..0bd6c82c5 100644 --- a/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java +++ b/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java @@ -34,7 +34,7 @@ public class NonSubscribedFeedsCleanerTest { feed.setLastRefreshAttempt(System.currentTimeMillis()); assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed)); - feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS)); + feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS)); assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed)); feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(200, TimeUnit.DAYS)); @@ -45,6 +45,26 @@ public class NonSubscribedFeedsCleanerTest { } @Test + public void testPlayedItem() { + Feed feed = createFeed(); + feed.setState(Feed.STATE_NOT_SUBSCRIBED); + FeedItem item = createItem(feed); + feed.getItems().add(item); + + item.setPlayed(false); + feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS)); + assertTrue(NonSubscribedFeedsCleaner.shouldDelete(feed)); + + item.setPlayed(true); + feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS)); + assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed)); + + item.setPlayed(true); + feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(100, TimeUnit.DAYS)); + assertTrue(NonSubscribedFeedsCleaner.shouldDelete(feed)); + } + + @Test public void testQueuedItem() { Feed feed = createFeed(); feed.setState(Feed.STATE_NOT_SUBSCRIBED); |