mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Merge pull request #8819 from apricot12/8694-Improve_subsvriptions_index_perfomance
8694 improve subscriptions index perfomance by eager loading tags, suppliers and exchanges.
This commit is contained in:
@@ -16,15 +16,16 @@ module Admin
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if view_context.subscriptions_setup_complete?(@shops)
|
||||
@order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user)
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user)
|
||||
@order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user).includes([:distributors, :cached_incoming_exchanges])
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).includes(:taggings)
|
||||
@payment_method_tags = payment_method_tags_by_id
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user)
|
||||
else
|
||||
@shop = @shops.first
|
||||
render :setup_explanation
|
||||
end
|
||||
end
|
||||
format.json { render_as_json @collection, ams_prefix: params[:ams_prefix] }
|
||||
format.json { render_as_json @collection, ams_prefix: params[:ams_prefix], payment_method_tags: payment_method_tags_by_id }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -165,5 +166,21 @@ module Admin
|
||||
@subscription_params ||= PermittedAttributes::Subscription.new(params).call.
|
||||
to_h.with_indifferent_access
|
||||
end
|
||||
|
||||
def payment_method_tags_by_id
|
||||
payment_method_tags = ::ActsAsTaggableOn::Tag.
|
||||
joins(:taggings).
|
||||
includes(:taggings).
|
||||
where(taggings: { taggable_type: "Spree::PaymentMethod",
|
||||
taggable_id: Spree::PaymentMethod.from(Enterprise.managed_by(spree_current_user).
|
||||
select('enterprises.id').find_by(id: params[:enterprise_id])),
|
||||
context: 'tags' })
|
||||
|
||||
payment_method_tags.each_with_object({}) do |tag, hash|
|
||||
payment_method_id = tag.taggings.first.taggable_id
|
||||
hash[payment_method_id] ||= []
|
||||
hash[payment_method_id] << tag.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,11 +7,19 @@ module Api
|
||||
attributes :id, :name, :type, :tag_list, :tags
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
payment_method_tag_list.join(",")
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map{ |t| { text: t } }
|
||||
payment_method_tag_list.map{ |t| { text: t } }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def payment_method_tag_list
|
||||
return object.tag_list unless options[:payment_method_tags]
|
||||
|
||||
options.dig(:payment_method_tags, object.id) || []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,9 +7,9 @@ module Api
|
||||
|
||||
def method_serializer
|
||||
if object.type == 'Spree::Gateway::StripeSCA'
|
||||
Api::Admin::PaymentMethod::StripeSerializer.new(object)
|
||||
Api::Admin::PaymentMethod::StripeSerializer.new(object, options)
|
||||
else
|
||||
Api::Admin::PaymentMethod::BaseSerializer.new(object)
|
||||
Api::Admin::PaymentMethod::BaseSerializer.new(object, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "shops", @shops, Api::Admin::IdNameSerializer if @shops
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "customers", @customers, Api::Admin::IdEmailSerializer if @customers
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "schedules", @schedules, Api::Admin::IdNameSerializer if @schedules
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "paymentMethods", @payment_methods, Api::Admin::PaymentMethodSerializer if @payment_methods
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "paymentMethods", @payment_methods, Api::Admin::PaymentMethodSerializer, { payment_method_tags: @payment_method_tags } if @payment_methods
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer if @shipping_methods
|
||||
= admin_inject_json_ams_array "admin.subscriptions", "orderCycles", @order_cycles, Api::Admin::BasicOrderCycleSerializer if @order_cycles
|
||||
= admin_inject_available_countries(module: "admin.subscriptions")
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
"storybook": "start-storybook"
|
||||
},
|
||||
"jest": {
|
||||
"testRegex": ["spec/javascripts/.*_test\\.js"],
|
||||
"transformIgnorePatterns": ["/node_modules/(?!(stimulus)/)"]
|
||||
"testRegex": [
|
||||
"spec/javascripts/.*_test\\.js"
|
||||
],
|
||||
"transformIgnorePatterns": [
|
||||
"/node_modules/(?!(stimulus)/)"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@storybook/addon-controls": "^6.4.13",
|
||||
|
||||
Reference in New Issue
Block a user