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.
This commit is contained in:
ByteHamster 2024-09-21 13:32:27 +02:00 committed by GitHub
parent 61cf9b3405
commit d3ec4139da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 4 deletions

View File

@ -1123,16 +1123,15 @@ public class PodDBAdapter {
} }
public Cursor getRandomEpisodesCursor(int limit, int seed) { 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 + ") " + " 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 // 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) + " AND " + KEY_PUBDATE + " > " + (System.currentTimeMillis() - 1000L * 3600L * 24L * 356L * 2)
// Hide episodes that have been played but not completed // Hide episodes that have been played but not completed
+ " AND (" + KEY_LAST_PLAYED_TIME + " == 0" + " AND (" + KEY_LAST_PLAYED_TIME + " == 0"
+ " OR " + KEY_LAST_PLAYED_TIME + " > " + (System.currentTimeMillis() - 1000L * 3600L) + ")" + " OR " + KEY_LAST_PLAYED_TIME + " > " + (System.currentTimeMillis() - 1000L * 3600L) + ")"
+ " AND " + SELECT_WHERE_FEED_IS_SUBSCRIBED + " AND " + SELECT_WHERE_FEED_IS_SUBSCRIBED;
+ " ORDER BY " + randomEpisodeNumber(seed); final String query = "SELECT MAX(" + randomEpisodeNumber(seed) + "), * FROM (" + allItems + ")"
final String query = "SELECT * FROM (" + allItemsRandomOrder + ")"
+ " GROUP BY " + KEY_FEED + " GROUP BY " + KEY_FEED
+ " ORDER BY " + randomEpisodeNumber(seed * 3) + " DESC LIMIT " + limit; + " ORDER BY " + randomEpisodeNumber(seed * 3) + " DESC LIMIT " + limit;
return db.rawQuery(query, null); return db.rawQuery(query, null);