Skip to content

Commit

Permalink
Fix N+1 issue on API of current_playlist song
Browse files Browse the repository at this point in the history
  • Loading branch information
aidewoode committed Aug 9, 2023
1 parent 451a3d4 commit dd2763d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/global_setting.rb
Expand Up @@ -13,7 +13,7 @@ module GlobalSetting
delegate :update, to: :instance

def instance
first_or_create!(singleton_guard: 0)
Current.setting ||= first_or_create!(singleton_guard: 0)
end

def has_setting(setting, type: :string, default: nil)
Expand Down
1 change: 1 addition & 0 deletions app/models/current.rb
Expand Up @@ -2,4 +2,5 @@

class Current < ActiveSupport::CurrentAttributes
attribute :user
attribute :setting
end
2 changes: 1 addition & 1 deletion app/views/api/v1/songs/_song.json.jbuilder
Expand Up @@ -2,7 +2,7 @@ json.call(song, :id, :name, :duration)
json.url need_transcode?(song) ? new_api_v1_transcoded_stream_url(song_id: song.id) : new_api_v1_stream_url(song_id: song.id)
json.album_name song.album.title
json.artist_name song.artist.title
json.is_favorited song.is_favorited || Current.user.favorited?(song)
json.is_favorited song.is_favorited.nil? ? Current.user.favorited?(song) : song.is_favorited
json.format need_transcode?(song) ? Stream::TRANSCODE_FORMAT : song.format
json.album_image_url do
json.small URI.join(root_url, image_url_for(song.album, size: "small"))
Expand Down

0 comments on commit dd2763d

Please sign in to comment.