Commit 036f0c50 authored by Nicolas Wavrant's avatar Nicolas Wavrant

Stock view optimization

See merge request !2017
parents 43b37458 d1c141da
...@@ -9,10 +9,33 @@ inventory_list_kw = { ...@@ -9,10 +9,33 @@ inventory_list_kw = {
'resource_uid': context.getUid(), '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: 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: 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: if quantity_unit:
inventory_list_kw['quantity_unit'] = quantity_unit inventory_list_kw['quantity_unit'] = quantity_unit
if metric_type: if metric_type:
......
from Products.PythonScripts.standard import Object from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
inventory_kw = { inventory_kw = {
'selection_domain': selection_domain '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: 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: 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: if quantity_unit:
inventory_kw['quantity_unit'] = quantity_unit inventory_kw['quantity_unit'] = quantity_unit
if metric_type: 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