Fix the smart shuffle spread calculation

We want to ensure that the total spread is divisible by all feed
sizes, so the modulo calculation needs to divide spread by the feed
size, not the other way round as is done currently.

In addition, this ensures the per-feed spread is never 0 (so the
degenerate case is equivalent to the old smart shuffle).

Signed-off-by: Stephen Kitt <steve@sk2.org>
This commit is contained in:
Stephen Kitt 2019-09-28 18:11:08 +02:00
parent d7f0f95ada
commit 7ae3934794
No known key found for this signature in database
GPG Key ID: 80D302F5886D839C

View File

@ -164,7 +164,7 @@ public class QueueSorter {
Collections.sort(feedItems, itemComparator);
if (spread == 0) {
spread = feedItems.size();
} else if (feedItems.size() % spread != 0){
} else if (spread % feedItems.size() != 0){
spread *= feedItems.size();
}
}
@ -180,6 +180,9 @@ public class QueueSorter {
Map<Long, List<FeedItem>> spreadItems = new HashMap<>();
for (List<FeedItem> feedItems : feeds) {
long thisSpread = spread / feedItems.size();
if (thisSpread == 0) {
thisSpread = 1;
}
// Starting from 0 ensures we front-load, so the queue starts with one episode from
// each feed in the queue
long itemSpread = 0;