From 6b189a0d472a523caf6de313b13eea23b466a278 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 14 Sep 2024 11:46:39 +0200 Subject: Delete non-subscribed, non-interacted feeds earlier (#7399) --- .../database/NonSubscribedFeedsCleaner.java | 9 +++++++-- .../database/NonSubscribedFeedsCleanerTest.java | 22 +++++++++++++++++++++- 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 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)); @@ -44,6 +44,26 @@ public class NonSubscribedFeedsCleanerTest { assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed)); } + @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(); -- cgit v1.2.3