From 93366c7a8603a64b410521dd19d967c0cd4d7e84 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 10 May 2026 09:10:01 +0300 Subject: internal/service: fix ListEpisodes global pagination by using cross-feed SQL query Previously ListEpisodes requested per-feed episodes with the full limit from every feed, concatenated them, and then sliced the resulting slice in memory. This silently skipped episodes from deeper pages because the per-feed DB limit never returned them. Fix: Add a new repository method ListEpisodesByFeedIDsWithStatus that takes a slice of feed IDs and applies LIMIT/OFFSET globally in a single SQL query (IN (...)). The service builds the feed ID list and delegates pagination to the database instead of emulating it in memory. Files changed: - internal/repository/podcast.go: add ListEpisodesByFeedIDsWithStatus - internal/repository/podcast_repo.go: extend PodcastRepo interface - internal/repository/mock.go: add mock implementation - internal/service/podcast.go: replace per-feed loop with new method - internal/service/podcast_test.go: add tests for ListEpisodes - internal/repository/podcast_test.go: add integration tests for new repo method - internal/api/handlers_test.go: add mockPingStore method --- internal/api/handlers_test.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'internal/api') diff --git a/internal/api/handlers_test.go b/internal/api/handlers_test.go index fc01ac0..eaeb665 100644 --- a/internal/api/handlers_test.go +++ b/internal/api/handlers_test.go @@ -1536,6 +1536,9 @@ func (m *mockPingStore) GetEpisodeByGUID(ctx context.Context, feedID int64, guid func (m *mockPingStore) ListEpisodesByFeed(ctx context.Context, feedID int64, limit, offset int) ([]model.PodcastEpisode, error) { return m.store.ListEpisodesByFeed(ctx, feedID, limit, offset) } +func (m *mockPingStore) ListEpisodesByFeedIDsWithStatus(ctx context.Context, userID int64, feedIDs []int64, limit, offset int) ([]model.PodcastEpisodeWithStatus, error) { + return m.store.ListEpisodesByFeedIDsWithStatus(ctx, userID, feedIDs, limit, offset) +} func (m *mockPingStore) UpdateEpisodeMedia(ctx context.Context, episodeID, mediaID int64, fileName string) error { return m.store.UpdateEpisodeMedia(ctx, episodeID, mediaID, fileName) } -- cgit v1.2.3