RSS feed returns all entries (unpaginated); db handles limit=0 as unlimited

This commit is contained in:
2026-07-06 11:57:44 +02:00
parent bef4f7ba1d
commit c25264c993
3 changed files with 28 additions and 7 deletions
@@ -224,15 +224,19 @@ public class DatabaseService {
sql += " AND primary_type IN (" + typePlaceholders + ")";
}
sql += " ORDER BY (CASE WHEN first_release_date IS NULL OR first_release_date = '' THEN 1 ELSE 0 END), first_release_date DESC";
sql += " LIMIT ? OFFSET ?";
boolean useLimit = limit > 0;
if (useLimit) sql += " LIMIT ? OFFSET ?";
try (Connection conn = getConnection();
PreparedStatement ps = conn.prepareStatement(sql)) {
int idx = 1;
for (var mbid : artistMbids) ps.setString(idx++, mbid);
for (var type : primaryTypes) ps.setString(idx++, type);
ps.setInt(idx++, limit + 1);
ps.setInt(idx, offset);
if (useLimit) {
ps.setInt(idx++, limit + 1);
ps.setInt(idx, offset);
}
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
groups.add(mapReleaseGroup(rs));
@@ -241,7 +245,7 @@ public class DatabaseService {
} catch (SQLException e) {
throw new RuntimeException(e);
}
boolean hasMore = groups.size() > limit;
boolean hasMore = useLimit && groups.size() > limit;
if (hasMore) groups.remove(groups.size() - 1);
return new FeedResult(groups, hasMore);
}
@@ -26,8 +26,25 @@ public class FeedService {
public static final int PAGE_SIZE = 20;
public List<ReleaseGroup> getFeedEntries() {
return getFeedEntries(1).entries();
public List<ReleaseGroup> getAllFeedEntries() {
var artists = artistService.findAll();
if (artists.isEmpty()) return List.of();
var artistMbids = new ArrayList<String>();
for (var a : artists) {
if (cacheService.needsRefresh(a.mbid())) {
var types = getMonitoredTypes(a);
releaseGroupService.fetchAndCache(a.mbid(), a.name(), types);
}
artistMbids.add(a.mbid());
}
var allTypes = List.of("Album", "Single", "EP", "Broadcast", "Other");
var monitoredTypes = new ArrayList<String>();
for (var a : artists) {
monitoredTypes.addAll(getMonitoredTypes(a));
}
return db.getFeed(artistMbids, monitoredTypes.isEmpty() ? allTypes : monitoredTypes, 0, 0).entries();
}
public FeedResult getFeedEntries(int page) {
@@ -22,7 +22,7 @@ public class FeedController {
@Path("/rss.xml")
@Produces(MediaType.APPLICATION_XML)
public Response rssFeed() {
var entries = feedService.getFeedEntries();
var entries = feedService.getAllFeedEntries();
var xml = feedBuilder.buildRss(entries);
return Response.ok(xml, MediaType.APPLICATION_XML).build();
}