From 5d73147628a64593d0e3bee5c0ba2adfe1b6933c Mon Sep 17 00:00:00 2001 From: "Justin Craig-Kuhn (JCK)" Date: Sun, 3 Nov 2024 18:09:23 -0800 Subject: [PATCH] Fix N+1s --- app/api/api_v2/shows.rb | 10 +++++++++- app/api/api_v2/tracks.rb | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/api/api_v2/shows.rb b/app/api/api_v2/shows.rb index 9e1ec6a0..6fa93406 100644 --- a/app/api/api_v2/shows.rb +++ b/app/api/api_v2/shows.rb @@ -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]) @@ -184,6 +190,8 @@ def show_by_date .includes( :venue, tracks: [ + :mp3_audio_attachment, + :png_waveform_attachment, { track_tags: :tag }, { songs: :songs_tracks } ], diff --git a/app/api/api_v2/tracks.rb b/app/api/api_v2/tracks.rb index 7ddb9975..b77968bb 100644 --- a/app/api/api_v2/tracks.rb +++ b/app/api/api_v2/tracks.rb @@ -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