Fix non-subscribed feed cleaner removing feed even when episode is queued (#7572)

This commit is contained in:
ByteHamster 2024-12-27 10:55:57 +01:00 committed by GitHub
parent 2617529896
commit 35241b64fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class NonSubscribedFeedsCleaner {
private static final String TAG = "NonSubscrFeedsCleaner";
@ -19,10 +20,17 @@ public class NonSubscribedFeedsCleaner {
if (feed.getState() != Feed.STATE_NOT_SUBSCRIBED) {
continue;
}
DBReader.getFeedItemList(feed, FeedItemFilter.unfiltered(), SortOrder.DATE_NEW_OLD, 0, Integer.MAX_VALUE);
DBReader.getFeedItemList(feed, new FeedItemFilter(FeedItemFilter.INCLUDE_NOT_SUBSCRIBED),
SortOrder.DATE_NEW_OLD, 0, Integer.MAX_VALUE);
DBReader.loadAdditionalFeedItemListData(feed.getItems());
if (shouldDelete(feed)) {
Log.d(TAG, "Deleting unsubscribed feed " + feed.getTitle());
DBWriter.deleteFeed(context, feed.getId());
try {
DBWriter.deleteFeed(context, feed.getId()).get();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
return;
}
}
feed.setItems(null); // Let it be garbage collected
}

View File

@ -1,16 +1,24 @@
package de.danoeh.antennapod.storage.database;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface;
import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfaceStub;
import de.danoeh.antennapod.storage.preferences.PlaybackPreferences;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -106,6 +114,40 @@ public class NonSubscribedFeedsCleanerTest {
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
}
@Test
public void integrationTest() throws ExecutionException, InterruptedException {
final Context context = InstrumentationRegistry.getInstrumentation().getContext();
final long longAgo = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(200, TimeUnit.DAYS);
// Initialize database
PlaybackPreferences.init(context);
DownloadServiceInterface.setImpl(new DownloadServiceInterfaceStub());
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
final Feed subscribedFeed = createFeed();
final Feed nonSubscribedFeed = createFeed();
nonSubscribedFeed.setState(Feed.STATE_NOT_SUBSCRIBED);
nonSubscribedFeed.setLastRefreshAttempt(longAgo);
final Feed nonSubscribedFeedFavorite = createFeed();
nonSubscribedFeedFavorite.setState(Feed.STATE_NOT_SUBSCRIBED);
nonSubscribedFeedFavorite.setLastRefreshAttempt(longAgo);
nonSubscribedFeedFavorite.getItems().add(createItem(nonSubscribedFeedFavorite));
DBWriter.setCompleteFeed(subscribedFeed, nonSubscribedFeedFavorite, nonSubscribedFeed).get();
DBWriter.addFavoriteItem(nonSubscribedFeedFavorite.getItems().get(0)).get();
NonSubscribedFeedsCleaner.deleteOldNonSubscribedFeeds(context);
List<Feed> feeds = DBReader.getFeedList();
assertEquals(2, feeds.size());
assertEquals(subscribedFeed.getId(), feeds.get(0).getId());
assertEquals(nonSubscribedFeedFavorite.getId(), feeds.get(1).getId());
}
private Feed createFeed() {
Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description",
"http://example.com/payment", "Daniel", "en", null, "http://example.com/feed",