Replace LEFT JOIN with INNER JOIN

I see no reason why a LEFT might be needed and its the root cause of the
awful performance.
This commit is contained in:
Pau Perez
2020-02-14 18:38:26 +01:00
parent 461b1b26f3
commit 53a63775fe
2 changed files with 7 additions and 1 deletions

View File

@@ -75,6 +75,12 @@ Spree::Order.class_eval do
joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)')
}
scope :with_line_items_variants_and_products, lambda {
joins('INNER JOIN spree_line_items ON (spree_line_items.order_id = spree_orders.id)').
joins('INNER JOIN spree_variants ON (spree_variants.id = spree_line_items.variant_id)').
joins('INNER JOIN spree_products ON (spree_products.id = spree_variants.product_id)')
}
scope :not_state, lambda { |state|
where("state != ?", state)
}

View File

@@ -10,7 +10,7 @@ module Permissions
# Find orders that the user can see
def visible_orders
Spree::Order.
with_line_items_variants_and_products_outer.
with_line_items_variants_and_products.
where(visible_orders_where_values)
end