mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Remove N+1 on variants and products
We get from an initial INNER JOIN with variants and products to fetch the variant overrides + N queries like: ```sql SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND "spree_variants"."id" = $1 LIMIT 1 [["id", 1545]] SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."id" = $1 LIMIT 1 [["id", 604]] ``` to the same initial INNER JOIN + just 2 queries like: ```sql SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND "spree_variants"."id" IN (1551, 1554) SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."deleted_at" IS NULL AND "spree_products"."id" IN (606, 607) ```
This commit is contained in:
@@ -76,6 +76,7 @@ module Admin
|
||||
def collection
|
||||
@variant_overrides = VariantOverride.
|
||||
joins(variant: :product).
|
||||
preload(variant: :product).
|
||||
for_hubs(params[:hub_id] || @hubs)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user