diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-10 09:10:01 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-10 09:10:01 +0300 |
| commit | 93366c7a8603a64b410521dd19d967c0cd4d7e84 (patch) | |
| tree | d9d2439921d02c07aa12e72a790ef3273c3384a8 /internal/api | |
| parent | 297a2f4e2f0aba6f139736030a7845e0d91e5856 (diff) | |
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
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/handlers_test.go | 3 |
1 files changed, 3 insertions, 0 deletions
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) } |
