From a049e7a4332ee98bae1019896d1a949545eb8067 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 3 Apr 2020 14:48:06 +0100 Subject: [PATCH 1/2] Add product to includes to avoid N+1 queries to fetch products when VO authorization is done right after this --- app/controllers/admin/variant_overrides_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index e12b43825b..b644536215 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -73,8 +73,10 @@ module Admin end def collection - @variant_overrides = VariantOverride.includes(:variant).for_hubs(params[:hub_id] || @hubs) - @variant_overrides.select { |vo| vo.variant.present? } + @variant_overrides = VariantOverride. + includes(variant: :product). + for_hubs(params[:hub_id] || @hubs). + select { |vo| vo.variant.present? } end def collection_actions From 452ab3a842dde430a0c084b9970dff76440fa286 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 3 Apr 2020 15:36:19 +0100 Subject: [PATCH 2/2] Add comment to better explain variant_override_set.collection_to_delete --- app/models/variant_override_set.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/variant_override_set.rb b/app/models/variant_override_set.rb index c64b4cdc32..d380df4144 100644 --- a/app/models/variant_override_set.rb +++ b/app/models/variant_override_set.rb @@ -15,8 +15,10 @@ class VariantOverrideSet < ModelSet tag_list.empty? end + # Override of ModelSet method to allow us to check presence of a tag_list (which is not an attribute) + # This method will delete VariantOverrides that have no values (see deletable? above) + # If the user sets all values to nil in the UI the VO will be deleted from the DB def collection_to_delete - # Override of ModelSet method to allow us to check presence of a tag_list (which is not an attribute) deleted = [] collection.delete_if { |e| deleted << e if @delete_if.andand.call(e.attributes, e.tag_list) } deleted