mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
This totally removes the following N+1 query from the GET /shops request
```sql
SELECT "spree_properties".* FROM "spree_properties"
INNER JOIN "spree_product_properties"
ON "spree_product_properties"."property_id" = "spree_properties"."id"
INNER JOIN "spree_products"
ON "spree_products"."id" = "spree_product_properties"."product_id"
INNER JOIN "enterprises"
ON "enterprises"."id" = "spree_products"."supplier_id"
WHERE "spree_products"."supplier_id" = 24;
```
The product properties of the corresponding enterprises are now loaded
in a single query fired from the controller.
15 lines
295 B
Ruby
15 lines
295 B
Ruby
class ShopsController < BaseController
|
|
layout 'darkswarm'
|
|
|
|
before_filter :enable_embedded_shopfront
|
|
|
|
def index
|
|
@enterprises = Enterprise
|
|
.activated
|
|
.includes(address: :state)
|
|
.includes(:properties)
|
|
.includes(supplied_products: :properties)
|
|
.all
|
|
end
|
|
end
|