I have four AR classes:
Artists (has many Releases)
Releases (has many ReleaseTracks)
Release Tracks (has many AudioTracks)
They are all also connected in the other direction (i.e. belongs_to).
My page displays audio tracks, grouped by release track, then release
then by artist.
Right now I fetch the artists and simply use the defined relationships
Loop through Artists
- Display Releases
** Display Release Tracks
*** Display Audio Tracks
This works but performance is terrible. With several thousand audio
and release tracks connected to hundreds of releases and dozens of
thousands of queries are processed each time this page loads.
AR is selecting the releases for each artist, the tracks for each
and the audio for each track, when many of the artists and releases have
Can anyone think of how I can optimize this?
Obviously, I could simply select the audio tracks but then I’m not sure
I would build the display so that artists and releases are grouped
in their hierarchy.
Any help is appreciated. Thanks much.