mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add primary_producer to index to reduce queries
This commit is contained in:
committed by
Maikel Linke
parent
666fbf53bf
commit
2b057a26d5
@@ -34,7 +34,8 @@ module ProductImport
|
||||
end
|
||||
|
||||
def count_existing_items
|
||||
@spreadsheet_data.suppliers_index.each do |_supplier_name, supplier_id|
|
||||
@spreadsheet_data.suppliers_index.each do |_supplier_name, attrs|
|
||||
supplier_id = attrs[:id]
|
||||
next unless supplier_id && permission_by_id?(supplier_id)
|
||||
|
||||
products_count =
|
||||
|
||||
@@ -63,8 +63,7 @@ module ProductImport
|
||||
end
|
||||
|
||||
def suppliers_index
|
||||
index = @spreadsheet_data.suppliers_index
|
||||
index.sort_by{ |_k, v| v.to_i }.reverse.to_h
|
||||
@spreadsheet_data.suppliers_index
|
||||
end
|
||||
|
||||
def supplier_products
|
||||
|
||||
@@ -30,8 +30,9 @@ module ProductImport
|
||||
@suppliers_index = {}
|
||||
@entries.each do |entry|
|
||||
supplier_name = entry.supplier
|
||||
supplier_id = @suppliers_index[supplier_name] || Enterprise.find_by_name(supplier_name, select: 'id, name').try(:id)
|
||||
@suppliers_index[supplier_name] = supplier_id
|
||||
next if @suppliers_index.key? supplier_name
|
||||
enterprise = Enterprise.find_by_name(supplier_name, select: 'id, name, is_primary_producer')
|
||||
@suppliers_index[supplier_name] = { id: enterprise.try(:id), is_primary_producer: enterprise.try(:is_primary_producer) }
|
||||
end
|
||||
@suppliers_index
|
||||
end
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
%h5= t('admin.product_import.import.options_and_defaults')
|
||||
%br
|
||||
|
||||
- @importer.suppliers_index.each do |name, supplier_id|
|
||||
- if name and supplier_id and @importer.permission_by_id?(supplier_id)
|
||||
- @importer.suppliers_index.each do |name, attrs|
|
||||
- if name and attrs[:id] and @importer.permission_by_id?(attrs[:id])
|
||||
%div.panel-section.import-settings
|
||||
%div.panel-header{ng: {click: 'togglePanel()', class: '{active: active}'}}
|
||||
%div.header-icon.success
|
||||
%i.fa.fa-check-circle
|
||||
%div.header-description
|
||||
= name
|
||||
- elsif name and supplier_id
|
||||
- elsif name and attrs[:id]
|
||||
%div.panel-section.import-settings
|
||||
%div.panel-header
|
||||
%div.header-icon.error
|
||||
|
||||
Reference in New Issue
Block a user