Skip to content

Commit

Permalink
Fix N+1s
Browse files Browse the repository at this point in the history
  • Loading branch information
jcraigk committed Nov 4, 2024
1 parent ca7a01c commit 5d73147
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/api/api_v2/shows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ class ApiV2::Shows < ApiV2::Base
def page_of_shows
Rails.cache.fetch("api/v2/shows?#{params.to_query}") do
shows = Show.published
.includes(:venue, show_tags: :tag)
.includes(
:venue,
:album_cover_attachment,
:album_zip_attachment,
:cover_art_attachment,
show_tags: :tag
)
.then { |s| apply_filter(s) }
.then { |s| apply_sort(s, :date, :desc) }
.paginate(page: params[:page], per_page: params[:per_page])
Expand Down Expand Up @@ -184,6 +190,8 @@ def show_by_date
.includes(
:venue,
tracks: [
:mp3_audio_attachment,
:png_waveform_attachment,
{ track_tags: :tag },
{ songs: :songs_tracks }
],
Expand Down
13 changes: 12 additions & 1 deletion app/api/api_v2/tracks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ class ApiV2::Tracks < ApiV2::Base
def page_of_tracks
Rails.cache.fetch("api/v2/tracks?#{params.to_query}") do
tracks = Track.includes(
:show,
:mp3_audio_attachment,
:png_waveform_attachment,
{
show: %i[
album_cover_attachment
album_zip_attachment
cover_art_attachment
tour
venue
show_tags
]
},
:songs,
{ track_tags: :tag },
:songs_tracks
Expand Down

0 comments on commit 5d73147

Please sign in to comment.