summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-09-21 13:32:27 +0200
committerGitHub <noreply@github.com>2024-09-21 13:32:27 +0200
commitd3ec4139da261b9f90a03458c139d38d325440e3 (patch)
tree51bcb64eba871eb892c0adc17ca25b29860040fd
parent61cf9b3405df202d9e2e5c86b18bc9c9585c6671 (diff)
downloadAntennaPod-d3ec4139da261b9f90a03458c139d38d325440e3.zip
Fix random episodes section not being random (#7416)
We used "GROUP BY" without specifying which item in the group to take. Apparently, SQLite then takes a deterministic item instead of the first (randomly sorted) item.
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java7
1 files changed, 3 insertions, 4 deletions
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
index 1e019e0e9..8f8d03927 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
@@ -1123,16 +1123,15 @@ public class PodDBAdapter {
}
public Cursor getRandomEpisodesCursor(int limit, int seed) {
- final String allItemsRandomOrder = SELECT_FEED_ITEMS_AND_MEDIA
+ final String allItems = SELECT_FEED_ITEMS_AND_MEDIA
+ " WHERE (" + KEY_READ + " = " + FeedItem.NEW + " OR " + KEY_READ + " = " + FeedItem.UNPLAYED + ") "
// Only from the last two years. Older episodes often contain broken covers and stuff like that
+ " AND " + KEY_PUBDATE + " > " + (System.currentTimeMillis() - 1000L * 3600L * 24L * 356L * 2)
// Hide episodes that have been played but not completed
+ " AND (" + KEY_LAST_PLAYED_TIME + " == 0"
+ " OR " + KEY_LAST_PLAYED_TIME + " > " + (System.currentTimeMillis() - 1000L * 3600L) + ")"
- + " AND " + SELECT_WHERE_FEED_IS_SUBSCRIBED
- + " ORDER BY " + randomEpisodeNumber(seed);
- final String query = "SELECT * FROM (" + allItemsRandomOrder + ")"
+ + " AND " + SELECT_WHERE_FEED_IS_SUBSCRIBED;
+ final String query = "SELECT MAX(" + randomEpisodeNumber(seed) + "), * FROM (" + allItems + ")"
+ " GROUP BY " + KEY_FEED
+ " ORDER BY " + randomEpisodeNumber(seed * 3) + " DESC LIMIT " + limit;
return db.rawQuery(query, null);