Commit d1c141da authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_pdm: speed up the Stock view of products

By pre-fetching some catalog entries to retrieve objects UIDs that can directly
be used in the inventory query, to avoid needless (costly) joins and hinting
the catalog to use the resource_section_node_uid index of the stock table.
parent 43b37458
Pipeline #38078 passed with stage
in 0 seconds
......@@ -9,10 +9,33 @@ inventory_list_kw = {
'resource_uid': context.getUid(),
}
# By passing node_uid and section_uid instead of node_category and
# section_category, we bypass 2 joins on category tables, and can
# directly use a good index:
# `resource_section_node_uid` (`resource_uid`,`section_uid`,`node_uid`,`simulation_state`)
# So it's better to run 2 catalog queries to retrieve the uid
# of the Organisations beforehand instead of confusing the catalog
# and making it go through huge joins (where no index can be used)
if node_category:
inventory_list_kw['node_category'] = node_category
node_uid_list = [
x.uid for x in portal.portal_catalog(
portal_type=portal.getPortalNodeTypeList(),
default_site_uid=portal.portal_categories.resolveCategory(node_category).getUid(),
)
]
if not node_uid_list:
return []
inventory_list_kw["node_uid"] = node_uid_list
if section_category:
inventory_list_kw['section_category'] = section_category
section_uid_list = [
x.uid for x in portal.portal_catalog(
portal_type=portal.getPortalNodeTypeList(),
default_group_uid=portal.portal_categories.resolveCategory(section_category).getUid(),
)
]
if not section_uid_list:
return []
inventory_list_kw['section_uid'] = section_uid_list
if quantity_unit:
inventory_list_kw['quantity_unit'] = quantity_unit
if metric_type:
......
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
inventory_kw = {
'selection_domain': selection_domain
}
# See Resource_getFutureInventoryList to understand why we
# run catalog queries to retrieve Organisations's uid
# instead of passing category paths to getInventory
if node_category:
inventory_kw['node_category'] = node_category
node_uid_list = [
x.uid for x in portal.portal_catalog(
portal_type=portal.getPortalNodeTypeList(),
default_site_uid=portal.portal_categories.resolveCategory(node_category).getUid(),
)
]
if not node_uid_list:
return []
inventory_kw["node_uid"] = node_uid_list
section_uid_list = None
if section_category:
inventory_kw['section_category'] = section_category
section_uid_list = [
x.uid for x in portal.portal_catalog(
portal_type=portal.getPortalNodeTypeList(),
default_group_uid=portal.portal_categories.resolveCategory(section_category).getUid(),
)
]
if not section_uid_list:
return []
inventory_kw['section_uid'] = section_uid_list
if quantity_unit:
inventory_kw['quantity_unit'] = quantity_unit
if metric_type:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment