Commit 55f2fd4d authored by Romain Courteaud's avatar Romain Courteaud Committed by Alain Takoudjou

Reduce number of JOIN

parent 21c51eb3
...@@ -116,31 +116,36 @@ class AcknowledgementTool(BaseTool): ...@@ -116,31 +116,36 @@ class AcknowledgementTool(BaseTool):
document_list = [] document_list = []
if user_name is not None: if user_name is not None:
portal = self.getPortalObject() portal = self.getPortalObject()
now = DateTime() person_value = portal.ERP5Site_getAuthenticatedMemberPersonValue(
# First look at all event that define the current user as destination user_name=user_name)
all_document_list = [x for x in \ if person_value is None:
self.portal_catalog(portal_type = portal_type, raise ValueError('No user found')
simulation_state = self.getPortalTransitInventoryStateList(), else:
# start_date = {'query':now,'range':'max'}, now = DateTime()
# stop_date = {'query':now,'range':'min'}, # First look at all event that define the current user as destination
default_destination_reference=user_name)] all_document_list = [x for x in \
# Now we can look directly at acknowledgement document not approved yet self.portal_catalog(portal_type = portal_type,
# so not in a final state simulation_state = self.getPortalTransitInventoryStateList(),
final_state_list = self.getPortalCurrentInventoryStateList() # start_date = {'query':now,'range':'max'},
query = NegatedQuery(Query(simulation_state=final_state_list)) # stop_date = {'query':now,'range':'min'},
all_document_list.extend([x for x in \ default_destination_uid=person_value.getUid())]
self.portal_catalog(portal_type = portal_type, # Now we can look directly at acknowledgement document not approved yet
query=query, # so not in a final state
# start_date = {'query':now,'range':'max'}, final_state_list = self.getPortalCurrentInventoryStateList()
# stop_date = {'query':now,'range':'min'}, query = NegatedQuery(Query(simulation_state=final_state_list))
destination_reference=user_name)]) all_document_list.extend([x for x in \
for document in all_document_list: self.portal_catalog(portal_type = portal_type,
# We filter manually on dates until a good solution is found for query=query,
# searching by dates on the catalog # start_date = {'query':now,'range':'max'},
if (document.getStartDate() < now < (document.getStopDate()+1)): # stop_date = {'query':now,'range':'min'},
acknowledged = document.isAcknowledged(user_name=user_name) default_destination_uid=person_value.getUid())])
if not acknowledged: for document in all_document_list:
document_list.append(document.getRelativeUrl()) # We filter manually on dates until a good solution is found for
# searching by dates on the catalog
if (document.getStartDate() < now < (document.getStopDate()+1)):
acknowledged = document.isAcknowledged(user_name=user_name)
if not acknowledged:
document_list.append(document.getRelativeUrl())
else: else:
raise ValueError('No user name given') raise ValueError('No user name given')
return document_list return document_list
......
  • What's the problem exactly with more JOINs ? Of course, the query was slower, but was it pathological to the point that filtering at ZODB level is faster ? Anyway, the following line crashes when stop_date is not defined:

              if (document.getStartDate() < now < (document.getStopDate()+1)):

    With Python 3, we'd have the same issue for start_date.

    /cc @seb @vpelletier @kazuhiko

  • The join which is avoided here is a category->catalog join, by replacing a $RELATION_$COLUMN with a $RELATION_uid condition. This is a good optimisation to me: ERP5 can quickly (or there is something seriously wrong in ERP5Site_getAuthenticatedMemberPersonValue) reach the most catalog-friendly value (an UID), so it should do that.

    I cannot comment on whether all destinations are necessarily Person documents - though it looks consistent with variable naming here.

  • Argg sorry for the noise. I had the feeling to see that this commit replaced catalog date comparison by Python. This commit is fine. I have a regression in my project but it seems to be elsewhere.

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