impress/app/controllers/alt_styles_controller.rb
Emi Matchu 9a3b33ea2f Preload many manifests concurrently for the Alt Styles page
I'm gonna also use this for a task to try to warm up *all* the
manifests in the database! But to start, just a simple one, to prepare
the alt styles page quickly on first run. (This doesn't really matter
in production now that I've already visited the page once, but it helps
when resetting things in dev, and I think more it's about establishing
the pattern!)
2024-02-23 13:45:12 -08:00

30 lines
817 B
Ruby

class AltStylesController < ApplicationController
def index
@alt_styles = AltStyle.includes(:species, :color, :swf_assets).
order(:species_id, :color_id)
if params[:species_id]
@species = Species.find(params[:species_id])
@alt_styles = @alt_styles.merge(@species.alt_styles)
end
# We're going to link to the HTML5 image URL, so make sure we have all the
# manifests ready!
SwfAsset.preload_manifests @alt_styles.map(&:swf_assets).flatten
respond_to do |format|
format.html { render }
format.json {
render json: @alt_styles.includes(swf_assets: [:zone]).as_json(
include: {
swf_assets: {
include: [:zone],
methods: [:html5_image_url, :html5_svg_url],
}
},
methods: [:series_name, :adjective_name, :thumbnail_url],
)
}
end
end
end