mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Cache enterprise supplied and distributed taxons
This commit is contained in:
@@ -23,7 +23,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
include SerializerHelper
|
||||
|
||||
attributes :orders_close_at, :active
|
||||
attributes :taxons, :supplied_taxons
|
||||
has_many :supplied_properties, serializer: Api::PropertySerializer
|
||||
has_many :distributed_properties, serializer: Api::PropertySerializer
|
||||
|
||||
@@ -59,18 +58,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties
|
||||
end
|
||||
|
||||
def taxons
|
||||
if active
|
||||
ids_to_objs options[:data].current_distributed_taxons[object.id]
|
||||
else
|
||||
ids_to_objs options[:data].all_distributed_taxons[object.id]
|
||||
end
|
||||
end
|
||||
|
||||
def supplied_taxons
|
||||
ids_to_objs options[:data].supplied_taxons[object.id]
|
||||
end
|
||||
end
|
||||
|
||||
class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
@@ -90,6 +77,8 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
:email_address, :hash, :logo, :promo_image, :path, :pickup, :delivery,
|
||||
:icon, :icon_font, :producer_icon_font, :category, :producers, :hubs
|
||||
|
||||
attributes :taxons, :supplied_taxons
|
||||
|
||||
has_one :address, serializer: Api::AddressSerializer
|
||||
|
||||
def pickup
|
||||
@@ -132,6 +121,22 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
ids_to_objs(relatives.andand[:distributors])
|
||||
end
|
||||
|
||||
def taxons
|
||||
if active
|
||||
ids_to_objs options[:data].current_distributed_taxons[object.id]
|
||||
else
|
||||
ids_to_objs options[:data].all_distributed_taxons[object.id]
|
||||
end
|
||||
end
|
||||
|
||||
def supplied_taxons
|
||||
ids_to_objs options[:data].supplied_taxons[object.id]
|
||||
end
|
||||
|
||||
def active
|
||||
options[:data].active_distributors.andand.include? object
|
||||
end
|
||||
|
||||
# Map svg icons.
|
||||
def icon
|
||||
icons = {
|
||||
|
||||
Reference in New Issue
Block a user