From 1e9937644991e59c284eda1d0107b4ba72703828 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 29 May 2024 18:52:36 -0700 Subject: [PATCH] Remove hundreds of unnecessary queries from `/alt-styles` page! I think the Rails query cache handled these anyway? But `SwfAsset` has a `before_save` hook that checks its zone's info, and `SwfAsset.preload_manifests` saves all the assets, on the assumption that saving is a no-op when the record didn't change anyway. And it basically is! But I figure that, now that I'm realizing hooks exist, simply not attempting to save unchanged records is probably a better representation of what we intend to do. So I'm fixing it like that! Another potential fix would be to preload the zones for these assets, but I think that confuses the intent too much; the method itself isn't using the zones, it's just a weird incidental thing that a save hook happens to use. (Would probably be better to refactor this old save hook into a different situation altogether, but that's for another time!) --- app/models/swf_asset.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index 2687b2ae..d1c53ba1 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -338,7 +338,7 @@ class SwfAsset < ApplicationRecord end SwfAsset.transaction do - swf_assets.each(&:save!) + swf_assets.select(&:changed?).each(&:save!) end end