Skip to content

Commit

Permalink
feat: Improve sorting of recent TV shows
Browse files Browse the repository at this point in the history
- Added a new condition to the query to ensure that only TV shows with at least one episode are returned.
- Modified the ordering of the results based on the maximum updated date of episodes.
- Removed commented out code.

This commit improves the sorting of recent TV shows by ensuring that only TV shows with at least one episode are included and ordering them based on the maximum updated date of episodes. It also removes unnecessary commented out code.
  • Loading branch information
Nouuu committed Jun 29, 2023
1 parent 4eafa11 commit 11fa337
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/repository/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ func (r *MediaRepository) GetAvailableRecentTvShows(page, limit int) ([]reposito
result := r.db.Table("tv_shows").
Joins("JOIN episodes ON episodes.tv_show_id = tv_shows.id").
Where("episodes.media_file_id IS NOT NULL").
//Order("episodes.updated_at DESC, episodes.created_at DESC").
Group("tv_shows.id").
Having("COUNT(DISTINCT episodes.id) > 0").
Having("MAX(episodes.updated_at) IS NOT NULL").
Order("MAX(episodes.updated_at) DESC").
Count(&count).
Offset(offset).
Limit(limit).
Expand All @@ -429,6 +430,7 @@ func (r *MediaRepository) GetAvailableRecentTvShows(page, limit int) ([]reposito
if result.Error != nil {
return nil, 0, result.Error
}

return tvShows, int(count), nil
}

Expand Down

0 comments on commit 11fa337

Please sign in to comment.