Delete non-subscribed, non-interacted feeds earlier (#7399)

This commit is contained in:
ByteHamster 2024-09-14 11:46:39 +02:00 committed by GitHub
parent 2a1b537d13
commit 6b189a0d47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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();