From 3eb40b2a4f999f2e16985db3a8bcc8a861c9767a Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 28 May 2024 17:05:04 -0700 Subject: [PATCH] Preload SWF asset manifests during wardrobe item search This doesn't matter a ton in production, where we already have most of our manifests loaded! But it matters a lot on my relatively-fresh development instance, at times like now when images.neopets.com is slow to respond. A single item search was taking minutes before this change (5 seconds of timeout per asset for 30 items!), but now takes a few seconds the first time, as it should! --- app/controllers/items_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index b58d577e..0a2544bf 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -171,7 +171,13 @@ class ItemsController < ApplicationController appearance_params[:color_id], appearance_params[:species_id]) end - target.appearances_for(@items.map(&:id), swf_asset_includes: [:zone]) + target.appearances_for(@items.map(&:id), swf_asset_includes: [:zone]). + tap do |appearances| + # Preload the manifests for these SWF assets concurrently, rather than + # loading them in sequence when we generate the JSON. + swf_assets = appearances.values.map(&:swf_assets).flatten + SwfAsset.preload_manifests(swf_assets) + end end def search_error(e)