Skip to content

Commit

Permalink
Show recently released albums on homepage
Browse files Browse the repository at this point in the history
Instead of recently_published. Lots of albums added are from an
Artists back catalogue, but I think here we want to show *new* music
so relying on released on is best. Not all artists set the release
date, but I think that's OK as there's enough that do for this list to
feel fresh.
  • Loading branch information
chrislo committed Dec 18, 2024
1 parent 852e8f6 commit 3f57829
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Album < ApplicationRecord
scope :pending, -> { where(publication_status: :pending) }
scope :in_release_order, -> { order(Arel.sql('COALESCE(released_on, first_published_on) DESC NULLS LAST')) }
scope :best_selling, -> { left_joins(:purchases).group(:id).order('COUNT(purchases.id) DESC') }
scope :recently_published, -> { order(first_published_on: :desc) }
scope :recently_released, -> { where.not(released_on: nil).order(released_on: :desc) }

after_commit :transcode_tracks, on: :update, if: :metadata_or_cover_changed?

Expand Down
4 changes: 2 additions & 2 deletions app/views/interests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

<div class="grid grid-col gap-6">
<%= render(
SectionComponent.new(title: 'Recently added')
SectionComponent.new(title: 'Recently released')
) do %>
<%= render(CardGridComponent.new) do %>
<% Album.recently_published.limit(4).each do |album| %>
<% Album.recently_released.limit(4).each do |album| %>
<%= link_to(artist_album_path(album.artist, album)) do %>
<%= render(CardComponent.new(
title: album.title,
Expand Down
11 changes: 6 additions & 5 deletions test/models/album_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ class AlbumTest < ActiveSupport::TestCase
artist1 = create(:artist)
artist2 = create(:artist)

older_album_artist1 = create(:album, artist: artist1, first_published_on: 4.months.ago)
newer_album_artist1 = create(:album, artist: artist1, first_published_on: 3.months.ago)
older_album_artist2 = create(:album, artist: artist2, first_published_on: 2.months.ago)
newer_album_artist2 = create(:album, artist: artist2, first_published_on: 1.month.ago)
older_album_artist1 = create(:album, artist: artist1, released_on: 4.months.ago)
newer_album_artist1 = create(:album, artist: artist1, released_on: 3.months.ago)
older_album_artist2 = create(:album, artist: artist2, released_on: 2.months.ago)
newer_album_artist2 = create(:album, artist: artist2, released_on: 1.month.ago)
create(:album, artist: artist1, released_on: nil)

recently_released = Album.recently_published.map(&:id)
recently_released = Album.recently_released.map(&:id)

assert_equal [newer_album_artist2.id,
older_album_artist2.id,
Expand Down

0 comments on commit 3f57829

Please sign in to comment.