From 917ca790af10340b552d8c885ba9acf7025a0a7d Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 4 Apr 2024 17:15:53 +1100 Subject: [PATCH 1/3] Temporarily add db counter to query This is going to be totally flaky so will remove soon. --- spec/system/admin/products_v3/products_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 74dcc2d051..af556bf494 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -16,6 +16,15 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do expect(page).to have_content "Bulk Edit Products" end + # TODO: this belongs in a unit or request spec + it "minimises db queries" do + create_products 16 + + expect{ + visit admin_products_url + }.to query_database 416.times # goodness me. Remember this includes user session updates etc. + end + describe "sorting" do let!(:product_b) { create(:simple_product, name: "Bananas") } let!(:product_a) { create(:simple_product, name: "Apples") } From 32b33de707527e46e4f393d7bac695c38daf55ef Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 4 Apr 2024 17:18:32 +1100 Subject: [PATCH 2/3] Optimise by pre-loading required columns Oh boy, that's a big change. --- app/controllers/admin/products_v3_controller.rb | 16 +++++++++------- spec/system/admin/products_v3/products_spec.rb | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index d328e4abfb..fb5efe5d1a 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -87,14 +87,16 @@ module Admin # Optimise by pre-loading required columns def product_query_includes - # TODO: add other fields used in columns? (eg supplier: [:name]) [ - # variants: [ - # :default_price, - # :stock_locations, - # :stock_items, - # :variant_overrides - # ] + :image, + :supplier, + { variants: [ + :default_price, + :primary_taxon, + :product, + :stock_items, + :tax_category, + ] }, ] end diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index af556bf494..ec588ec7d7 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -22,7 +22,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do expect{ visit admin_products_url - }.to query_database 416.times # goodness me. Remember this includes user session updates etc. + }.to query_database 243.times # Remember this includes user session updates etc. end describe "sorting" do From 18d91d166e8633dcc025566243bfab631e7882a2 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 10 Apr 2024 15:36:45 +1000 Subject: [PATCH 3/3] Remove temporary spec It's likely to change frequently when there are global changes to the admin screen. It would be better to test more directly, but I don't think worth it while everythings moving around so much. --- spec/system/admin/products_v3/products_spec.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index ec588ec7d7..74dcc2d051 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -16,15 +16,6 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do expect(page).to have_content "Bulk Edit Products" end - # TODO: this belongs in a unit or request spec - it "minimises db queries" do - create_products 16 - - expect{ - visit admin_products_url - }.to query_database 243.times # Remember this includes user session updates etc. - end - describe "sorting" do let!(:product_b) { create(:simple_product, name: "Bananas") } let!(:product_a) { create(:simple_product, name: "Apples") }