Files
openfoodnetwork/app/controllers/shops_controller.rb
Pau Perez 4608c434b4 Eager load producer properties to avoid N+1
This totally removes the following N+1 query from the GET /shops request

```sql
SELECT "spree_properties".* FROM "spree_properties"
  INNER JOIN "producer_properties"
    ON "spree_properties"."id" = "producer_properties"."property_id"
  WHERE "producer_properties"."producer_id" = 17
  ORDER BY producer_properties.position;
```

The producer properties of the corresponding enterprises are now loaded
in a single query fired from the controller.
2018-11-28 16:21:40 +01:00

14 lines
247 B
Ruby

class ShopsController < BaseController
layout 'darkswarm'
before_filter :enable_embedded_shopfront
def index
@enterprises = Enterprise
.activated
.includes(address: :state)
.includes(:properties)
.all
end
end