mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 23:49:19 +00:00
Merge pull request #29639 from marination/item-variants-perf
perf: Weed out disabled variants via sql query instead of pythonic looping separately
This commit is contained in:
@@ -66,26 +66,24 @@ class ItemVariantsCacheManager:
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
# join with Website Item
|
# Get Variants and tehir Attributes that are not disabled
|
||||||
item_variants_data = frappe.get_all(
|
iva = frappe.qb.DocType("Item Variant Attribute")
|
||||||
'Item Variant Attribute',
|
item = frappe.qb.DocType("Item")
|
||||||
{'variant_of': parent_item_code},
|
query = (
|
||||||
['parent', 'attribute', 'attribute_value'],
|
frappe.qb.from_(iva)
|
||||||
order_by='name',
|
.join(item).on(item.name == iva.parent)
|
||||||
as_list=1
|
.select(
|
||||||
)
|
iva.parent, iva.attribute, iva.attribute_value
|
||||||
|
).where(
|
||||||
disabled_items = set(
|
(iva.variant_of == parent_item_code)
|
||||||
[i.name for i in frappe.db.get_all('Item', {'disabled': 1})]
|
& (item.disabled == 0)
|
||||||
|
).orderby(iva.name)
|
||||||
)
|
)
|
||||||
|
item_variants_data = query.run()
|
||||||
|
|
||||||
attribute_value_item_map = frappe._dict()
|
attribute_value_item_map = frappe._dict()
|
||||||
item_attribute_value_map = frappe._dict()
|
item_attribute_value_map = frappe._dict()
|
||||||
|
|
||||||
# dont consider variants that are disabled
|
|
||||||
# pull all other variants
|
|
||||||
item_variants_data = [r for r in item_variants_data if r[0] not in disabled_items]
|
|
||||||
|
|
||||||
for row in item_variants_data:
|
for row in item_variants_data:
|
||||||
item_code, attribute, attribute_value = row
|
item_code, attribute, attribute_value = row
|
||||||
# (attr, value) => [item1, item2]
|
# (attr, value) => [item1, item2]
|
||||||
@@ -124,4 +122,7 @@ def build_cache(item_code):
|
|||||||
def enqueue_build_cache(item_code):
|
def enqueue_build_cache(item_code):
|
||||||
if frappe.cache().hget('item_cache_build_in_progress', item_code):
|
if frappe.cache().hget('item_cache_build_in_progress', item_code):
|
||||||
return
|
return
|
||||||
frappe.enqueue(build_cache, item_code=item_code, queue='long')
|
frappe.enqueue(
|
||||||
|
"erpnext.e_commerce.variant_selector.item_variants_cache.build_cache",
|
||||||
|
item_code=item_code, queue='long'
|
||||||
|
)
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ class TestVariantSelector(ERPNextTestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
make_web_item_price(item_code="Test-Tshirt-Temp-S-R", price_list_rate=100)
|
make_web_item_price(item_code="Test-Tshirt-Temp-S-R", price_list_rate=100)
|
||||||
|
|
||||||
|
frappe.local.shopping_cart_settings = None # clear cached settings values
|
||||||
next_values = get_next_attribute_and_values(
|
next_values = get_next_attribute_and_values(
|
||||||
"Test-Tshirt-Temp",
|
"Test-Tshirt-Temp",
|
||||||
selected_attributes={"Test Size": "Small", "Test Colour": "Red"}
|
selected_attributes={"Test Size": "Small", "Test Colour": "Red"}
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ $.extend(erpnext.item, {
|
|||||||
let selected_attributes = {};
|
let selected_attributes = {};
|
||||||
me.multiple_variant_dialog.$wrapper.find('.form-column').each((i, col) => {
|
me.multiple_variant_dialog.$wrapper.find('.form-column').each((i, col) => {
|
||||||
if(i===0) return;
|
if(i===0) return;
|
||||||
let attribute_name = $(col).find('label').html();
|
let attribute_name = $(col).find('label').html().trim();
|
||||||
selected_attributes[attribute_name] = [];
|
selected_attributes[attribute_name] = [];
|
||||||
let checked_opts = $(col).find('.checkbox input');
|
let checked_opts = $(col).find('.checkbox input');
|
||||||
checked_opts.each((i, opt) => {
|
checked_opts.each((i, opt) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user