Delete non-subscribed, non-interacted feeds earlier (#7399)
This commit is contained in:
parent
2a1b537d13
commit
6b189a0d47
|
@ -10,7 +10,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class NonSubscribedFeedsCleaner {
|
public class NonSubscribedFeedsCleaner {
|
||||||
private static final String TAG = "NonSubscrFeedsCleaner";
|
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) {
|
public static void deleteOldNonSubscribedFeeds(Context context) {
|
||||||
List<Feed> feeds = DBReader.getFeedList();
|
List<Feed> feeds = DBReader.getFeedList();
|
||||||
|
@ -35,6 +36,10 @@ public class NonSubscribedFeedsCleaner {
|
||||||
} else if (feed.hasEpisodeInApp()) {
|
} else if (feed.hasEpisodeInApp()) {
|
||||||
return false;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class NonSubscribedFeedsCleanerTest {
|
||||||
feed.setLastRefreshAttempt(System.currentTimeMillis());
|
feed.setLastRefreshAttempt(System.currentTimeMillis());
|
||||||
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
|
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));
|
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
|
||||||
|
|
||||||
feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(200, TimeUnit.DAYS));
|
feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(200, TimeUnit.DAYS));
|
||||||
|
@ -44,6 +44,26 @@ public class NonSubscribedFeedsCleanerTest {
|
||||||
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
|
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
|
@Test
|
||||||
public void testQueuedItem() {
|
public void testQueuedItem() {
|
||||||
Feed feed = createFeed();
|
Feed feed = createFeed();
|
||||||
|
|
Loading…
Reference in New Issue