Commit 9c869eb9 authored by Julien Muchembled's avatar Julien Muchembled

Optimize a few loops over subobjects + setdefault abuse

- contentValues(filter) is really slow
- portal should be explicitly retrieved before using one of its methods
parent 5fad4433
...@@ -102,9 +102,9 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -102,9 +102,9 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
base_contribution must be a relative url of a category. If passed, then base_contribution must be a relative url of a category. If passed, then
fast parameter is ignored. fast parameter is ignored.
""" """
result = None if 'portal_type' not in kw:
kw.setdefault( 'portal_type', kw['portal_type'] = self.getPortalObject() \
self.getPortalDeliveryMovementTypeList()) .getPortalDeliveryMovementTypeList()
if base_contribution is None: if base_contribution is None:
if fast: if fast:
# XXX fast ignores base_contribution for now, but it should be possible # XXX fast ignores base_contribution for now, but it should be possible
...@@ -160,7 +160,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -160,7 +160,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
portal types. You should use getTotalPrice(base_contribution=) instead. portal types. You should use getTotalPrice(base_contribution=) instead.
""" """
total_price = self.getTotalPrice(fast=fast, src__=src__, **kw) total_price = self.getTotalPrice(fast=fast, src__=src__, **kw)
kw['portal_type'] = self.getPortalTaxMovementTypeList() kw['portal_type'] = self.getPortalObject().getPortalTaxMovementTypeList()
return total_price + self.getTotalPrice(fast=fast, src__=src__, **kw) return total_price + self.getTotalPrice(fast=fast, src__=src__, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -175,8 +175,9 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -175,8 +175,9 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
So if the order is not in the catalog, getTotalQuantity(fast=1) So if the order is not in the catalog, getTotalQuantity(fast=1)
will return 0, this is not a bug. will return 0, this is not a bug.
""" """
kw.setdefault('portal_type', if 'portal_type' not in kw:
self.getPortalDeliveryMovementTypeList()) kw['portal_type'] = self.getPortalObject() \
.getPortalDeliveryMovementTypeList()
if fast: if fast:
kw['section_uid'] = self.getDestinationSectionUid() kw['section_uid'] = self.getDestinationSectionUid()
kw['stock.explanation_uid'] = self.getUid() kw['stock.explanation_uid'] = self.getUid()
...@@ -272,7 +273,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -272,7 +273,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
This does not contain Container Line or Container Cell. This does not contain Container Line or Container Cell.
""" """
return self.getMovementList(portal_type= return self.getMovementList(portal_type=
self.getPortalSimulatedMovementTypeList()) self.getPortalObject().getPortalSimulatedMovementTypeList())
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getInvoiceMovementList') 'getInvoiceMovementList')
...@@ -282,7 +283,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -282,7 +283,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
This does not contain Container Line or Container Cell. This does not contain Container Line or Container Cell.
""" """
return self.getMovementList(portal_type= return self.getMovementList(portal_type=
self.getPortalInvoiceMovementTypeList()) self.getPortalObject().getPortalInvoiceMovementTypeList())
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getContainerList') 'getContainerList')
...@@ -291,11 +292,8 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -291,11 +292,8 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
Return a list of root containers. Return a list of root containers.
This does not contain sub-containers. This does not contain sub-containers.
""" """
container_list = [] return self.objectValues(portal_type=
for m in self.contentValues(filter={'portal_type': self.getPortalObject().getPortalContainerTypeList())
self.getPortalContainerTypeList()}):
container_list.append(m)
return container_list
####################################################### #######################################################
# Causality computation # Causality computation
...@@ -460,13 +458,11 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -460,13 +458,11 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
####################################################### #######################################################
# Stock Management # Stock Management
def _getMovementResourceList(self): def _getMovementResourceList(self):
resource_dict = {} resource_set = {m.getResource()
for m in self.contentValues(filter={ for m in self.objectValues(portal_type=
'portal_type': self.getPortalMovementTypeList()}): self.getPortalObject().getPortalMovementTypeList())}
r = m.getResource() resource_set.discard(None)
if r is not None: return list(resource_set)
resource_dict[r] = 1
return resource_dict.keys()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getInventory') 'getInventory')
...@@ -698,11 +694,10 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -698,11 +694,10 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
return self.asComposedDocument().build(explanation=self) return self.asComposedDocument().build(explanation=self)
def _createRootAppliedRule(self): def _createRootAppliedRule(self):
portal = self.getPortalObject()
# Only create RAR if we are not in a "too early" or "too late" state. # Only create RAR if we are not in a "too early" or "too late" state.
state = self.getSimulationState() state = self.getSimulationState()
if (state != 'deleted' and if (state != 'deleted' and
state not in portal.getPortalDraftOrderStateList()): state not in self.getPortalObject().getPortalDraftOrderStateList()):
return super(Delivery, self)._createRootAppliedRule() return super(Delivery, self)._createRootAppliedRule()
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
......
...@@ -260,7 +260,7 @@ class DeliveryLine(Movement, XMLMatrix, ImmobilisationMovement): ...@@ -260,7 +260,7 @@ class DeliveryLine(Movement, XMLMatrix, ImmobilisationMovement):
portal_type = 'Simulation Movement'): portal_type = 'Simulation Movement'):
# And apply # And apply
getattr(my_simulation_movement.getObject(), method_id)() getattr(my_simulation_movement.getObject(), method_id)()
for c in self.contentValues(filter={'portal_type': 'Delivery Cell'}): for c in self.objectValues(portal_type='Delivery Cell'):
for my_simulation_movement in c.getDeliveryRelatedValueList( for my_simulation_movement in c.getDeliveryRelatedValueList(
portal_type = 'Simulation Movement'): portal_type = 'Simulation Movement'):
# And apply # And apply
...@@ -359,11 +359,11 @@ class DeliveryLine(Movement, XMLMatrix, ImmobilisationMovement): ...@@ -359,11 +359,11 @@ class DeliveryLine(Movement, XMLMatrix, ImmobilisationMovement):
"""Returns a list of messages that contains the divergences for that line """Returns a list of messages that contains the divergences for that line
and the cells it may contain. and the cells it may contain.
""" """
divergence_list = []
if self.hasCellContent(): if self.hasCellContent():
for cell in self.contentValues(filter={ divergence_list = []
'portal_type': self.getPortalDeliveryMovementTypeList()}): for cell in self.objectValues(portal_type=self.getPortalObject()
divergence_list.extend(cell.getDivergenceList()) .getPortalDeliveryMovementTypeList()):
divergence_list += cell.getDivergenceList()
return divergence_list return divergence_list
else: else:
return Movement.getDivergenceList(self) return Movement.getDivergenceList(self)
......
...@@ -119,7 +119,9 @@ class Order(Delivery): ...@@ -119,7 +119,9 @@ class Order(Delivery):
def getTotalQuantity(self, **kw) : def getTotalQuantity(self, **kw) :
"""Returns the total quantity for this Order. """ """Returns the total quantity for this Order. """
kw.setdefault('portal_type', self.getPortalOrderMovementTypeList()) if 'portal_type' not in kw:
kw['portal_type'] = self.getPortalObject() \
.getPortalOrderMovementTypeList()
if kw.get('fast'): if kw.get('fast'):
kw['only_accountable'] = False kw['only_accountable'] = False
return Delivery.getTotalQuantity(self, **kw) return Delivery.getTotalQuantity(self, **kw)
......
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