Commit 5f0c0f5f authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Boxiang Sun

all: Avoid most direct calls to {recursiveI,i}mmediateReindexObject

These methods must not be called synchronously:
- they can break catalog by not being careful enough about other
  reindexations which may happen in parallel. See the serialization_tag
  mechanism for more.
- indexation gets executed in the security context of the user causing the
  call, which may lead to an indexation result different from what happens
  when indexation happens with an all-accesses user.
parent b72ee3b9
...@@ -25,11 +25,10 @@ if (len(recovery_list) > 0): ...@@ -25,11 +25,10 @@ if (len(recovery_list) > 0):
module = portal.getDefaultModule(portal_type='Credential Recovery') module = portal.getDefaultModule(portal_type='Credential Recovery')
credential_recovery = module.newContent( credential_recovery = module.newContent(
reindex_on_commit=True,
portal_type="Credential Recovery", portal_type="Credential Recovery",
reference=context.getReference(), reference=context.getReference(),
destination_decision_value=context, destination_decision_value=context,
language=portal.Localizer.get_selected_language()) language=portal.Localizer.get_selected_language())
# immediate reindex allowed because it is a new object
credential_recovery.immediateReindexObject()
context.serialize() context.serialize()
credential_recovery.submit() credential_recovery.submit()
...@@ -8,11 +8,11 @@ if portal.portal_preferences.getPreferredNumberOfLastPasswordToCheck() or \ ...@@ -8,11 +8,11 @@ if portal.portal_preferences.getPreferredNumberOfLastPasswordToCheck() or \
# save password and modification date # save password and modification date
current_password = login.getPassword() current_password = login.getPassword()
if current_password is not None: if current_password is not None:
password_event = portal.system_event_module.newContent(portal_type='Password Event', portal.system_event_module.newContent(
source_value=login, # Person_isPasswordExpired cache the wrong result if document is not in catalog.
destination_value=login, reindex_on_commit=True,
password=current_password) portal_type='Password Event',
password_event.confirm() source_value=login,
# Person_isPasswordExpired cache the wrong result if document is not in catalog. destination_value=login,
# As the document is created in the same transaction, it is possible to force reindexation password=current_password,
password_event.immediateReindexObject() ).confirm()
...@@ -9,14 +9,11 @@ module_list = ['document_module', ...@@ -9,14 +9,11 @@ module_list = ['document_module',
'web_page_module', 'web_page_module',
'web_site_module'] 'web_site_module']
context.portal_types.recursiveImmediateReindexObject() context.portal_types.Folder_reindexAll()
portal = context.getPortalObject() portal = context.getPortalObject()
for module_id in module_list: for module_id in module_list:
module = getattr(portal, module_id) stack = [getattr(portal, module_id)]
module.recursiveImmediateReindexObject()
stack = [module]
for obj in stack: for obj in stack:
for child in obj.objectValues(): for child in obj.objectValues():
stack.append(child) stack.append(child)
obj.updateLocalRolesOnSecurityGroups() obj.updateLocalRolesOnSecurityGroups()
obj.reindexObjectSecurity()
...@@ -29,6 +29,7 @@ else: ...@@ -29,6 +29,7 @@ else:
# create the person wich represent the company # create the person wich represent the company
person_module = portal.getDefaultModule(portal_type='Person') person_module = portal.getDefaultModule(portal_type='Person')
accountant = person_module.newContent(portal_type='Person', accountant = person_module.newContent(portal_type='Person',
reindex_on_commit=True,
title=changed_object.getAccountantName(), title=changed_object.getAccountantName(),
default_telephone_text=changed_object.getAccountantTelNumber(), default_telephone_text=changed_object.getAccountantTelNumber(),
default_fax_text=changed_object.getAccountantFax(), default_fax_text=changed_object.getAccountantFax(),
...@@ -51,6 +52,5 @@ assignment.open() ...@@ -51,6 +52,5 @@ assignment.open()
login = context.generateNewLogin(text=changed_object.getAccountantName()) login = context.generateNewLogin(text=changed_object.getAccountantName())
password = changed_object.Person_generatePassword() password = changed_object.Person_generatePassword()
context.EGov_setLoginAndPasswordAsManager(accountant, login, password) context.EGov_setLoginAndPasswordAsManager(accountant, login, password)
accountant.immediateReindexObject()
accountant.Person_sendCrendentialsByEMail() accountant.Person_sendCrendentialsByEMail()
pad = context.knowledge_pad_module.newContent(portal_type='Knowledge Pad', pad = context.knowledge_pad_module.newContent(portal_type='Knowledge Pad',
reindex_on_commit=True,
title = pad_title) title = pad_title)
# for web mode # for web mode
if mode in ('web_front', 'web_section',): if mode in ('web_front', 'web_section',):
...@@ -9,9 +10,6 @@ if mode in ('web_front', 'web_section',): ...@@ -9,9 +10,6 @@ if mode in ('web_front', 'web_section',):
# set it as active # set it as active
context.ERP5Site_toggleActiveKnowledgePad(pad, mode=mode, redirect=False) context.ERP5Site_toggleActiveKnowledgePad(pad, mode=mode, redirect=False)
# See ERP5Site_createDefaultKnowledgePadListForUser
pad.immediateReindexObject()
if redirect_url: if redirect_url:
return context.REQUEST.RESPONSE.redirect(redirect_url) return context.REQUEST.RESPONSE.redirect(redirect_url)
else: else:
......
...@@ -37,6 +37,7 @@ for pref in (system_pref, user_pref): ...@@ -37,6 +37,7 @@ for pref in (system_pref, user_pref):
else: else:
# created empty one because no template found # created empty one because no template found
knowledge_pad = context.knowledge_pad_module.newContent( knowledge_pad = context.knowledge_pad_module.newContent(
reindex_on_commit=True,
portal_type = 'Knowledge Pad', portal_type = 'Knowledge Pad',
title = context.Base_translateString('Tab 1')) title = context.Base_translateString('Tab 1'))
if is_web_mode: if is_web_mode:
...@@ -62,12 +63,5 @@ if owner is not None: ...@@ -62,12 +63,5 @@ if owner is not None:
# set default gadgets # set default gadgets
context.ERP5Site_createDefaultKnowledgeBox(knowledge_pad) context.ERP5Site_createDefaultKnowledgeBox(knowledge_pad)
# Calling immediateReindexObject explicitly is a coding crime.
# But it's safe for newly created objects and this script should
# be called rarely enough to not cause any performance issue.
# Any other solution would be more complicated.
# See also ERP5Site_addNewKnowledgePad
knowledge_pad.immediateReindexObject()
if REQUEST is None: if REQUEST is None:
return knowledge_pad return knowledge_pad
...@@ -8,6 +8,7 @@ project_list = portal.portal_catalog(portal_type="Project", id=project) # with i ...@@ -8,6 +8,7 @@ project_list = portal.portal_catalog(portal_type="Project", id=project) # with i
project_object = project_list[0].getObject() project_object = project_list[0].getObject()
support_request = portal.support_request_module.newContent( support_request = portal.support_request_module.newContent(
reindex_on_commit=True,
portal_type='Support Request', portal_type='Support Request',
title=title, title=title,
resource="service_module/" + resource, resource="service_module/" + resource,
...@@ -34,7 +35,6 @@ support_request.edit( ...@@ -34,7 +35,6 @@ support_request.edit(
support_request.submit() support_request.submit()
support_request.immediateReindexObject()
if description is not None or file is not None: if description is not None or file is not None:
portal.post_module.PostModule_createHTMLPostForSupportRequest( portal.post_module.PostModule_createHTMLPostForSupportRequest(
......
...@@ -35,6 +35,9 @@ for container_number in range(container_count) : ...@@ -35,6 +35,9 @@ for container_number in range(container_count) :
# we use container_type to know which are the resource (and variation) # we use container_type to know which are the resource (and variation)
# of the container # of the container
container = delivery.newContent( container = delivery.newContent(
# Container must be immediately reindexed,
# in order to see good packed quantity in fast input form
reindex_on_commit=True,
portal_type="Container", portal_type="Container",
title=new_container_id, title=new_container_id,
int_index=next_container_number, int_index=next_container_number,
...@@ -94,10 +97,6 @@ for container_number in range(container_count) : ...@@ -94,10 +97,6 @@ for container_number in range(container_count) :
line_variation_base_category_list) line_variation_base_category_list)
cell.edit(quantity=quantity) cell.edit(quantity=quantity)
# Container must be immediately reindexed,
# in order to see good packed quantity in fast input form
container.recursiveImmediateReindexObject()
url_params = make_query(selection_name=selection_name, url_params = make_query(selection_name=selection_name,
dialog_category=dialog_category, dialog_category=dialog_category,
form_id=form_id, form_id=form_id,
......
...@@ -787,7 +787,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase): ...@@ -787,7 +787,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
# getTotalPrice uses mysql, so we must make sure the invoice is cataloged # getTotalPrice uses mysql, so we must make sure the invoice is cataloged
# to have correct results # to have correct results
invoice_line.getParentValue().recursiveImmediateReindexObject() self.tic()
self.assertEqual(invoice_line.getTotalPrice(), 100) self.assertEqual(invoice_line.getTotalPrice(), 100)
self.assertEqual(invoice_line.getTotalQuantity(), 10) self.assertEqual(invoice_line.getTotalQuantity(), 10)
......
...@@ -149,7 +149,7 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase): ...@@ -149,7 +149,7 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
self.assertEqual(transmission_sheet.getValidationState(), 'draft') self.assertEqual(transmission_sheet.getValidationState(), 'draft')
# add an invoice to the transamission sheet # add an invoice to the transamission sheet
invoice.setAggregateValue(transmission_sheet) invoice.setAggregateValue(transmission_sheet)
invoice.recursiveImmediateReindexObject() self.tic()
self.getWorkflowTool().doActionFor( self.getWorkflowTool().doActionFor(
transmission_sheet, transmission_sheet,
'emit_action') 'emit_action')
......
...@@ -6808,7 +6808,7 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6808,7 +6808,7 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(initial___ac_local_roles_group_id_dict__, self.assertEqual(initial___ac_local_roles_group_id_dict__,
path.__ac_local_roles_group_id_dict__) path.__ac_local_roles_group_id_dict__)
# make sure we can reindexing the object works # make sure we can reindexing the object works
path.recursiveImmediateReindexObject() path.recursiveReindexObject()
self.tic() self.tic()
finally: finally:
# restore state # restore state
......
...@@ -1336,7 +1336,6 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase): ...@@ -1336,7 +1336,6 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
action = transition_step['action'] action = transition_step['action']
LOG("Transiting '%s' on packing list %s" % (action, transition_step['id']), 0, '') LOG("Transiting '%s' on packing list %s" % (action, transition_step['id']), 0, '')
workflow_tool.doActionFor(transited_pl, action, packing_list_workflow) workflow_tool.doActionFor(transited_pl, action, packing_list_workflow)
transited_pl.recursiveImmediateReindexObject() # XXX
self.tic() self.tic()
for omit_transit in (0,1): for omit_transit in (0,1):
......
...@@ -861,7 +861,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -861,7 +861,7 @@ class TestPackingListMixin(TestOrderMixin):
if quantity is None: if quantity is None:
quantity = sequence.get('line_quantity',self.default_quantity) quantity = sequence.get('line_quantity',self.default_quantity)
container_line.edit(quantity=quantity) container_line.edit(quantity=quantity)
container_line.immediateReindexObject() self.tic()
def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None, def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None,
quantity=None,**kw): quantity=None,**kw):
...@@ -882,7 +882,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -882,7 +882,7 @@ class TestPackingListMixin(TestOrderMixin):
if not line.hasCellContent(): if not line.hasCellContent():
quantity = line.getQuantity() quantity = line.getQuantity()
container_line.edit(quantity=quantity) container_line.edit(quantity=quantity)
container_line.immediateReindexObject() self.tic()
self.assertEqual(quantity, container_line.getQuantity()) self.assertEqual(quantity, container_line.getQuantity())
self.assertEqual(quantity, container_line.getTotalQuantity()) self.assertEqual(quantity, container_line.getTotalQuantity())
# with variation # with variation
...@@ -903,7 +903,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -903,7 +903,7 @@ class TestPackingListMixin(TestOrderMixin):
quantity=old_cell.getQuantity(), quantity=old_cell.getQuantity(),
predicate_category_list=cell_key, predicate_category_list=cell_key,
variation_category_list=cell_key) variation_category_list=cell_key)
cell.immediateReindexObject() self.tic()
self.assertEqual(old_cell.getQuantity(), cell.getQuantity()) self.assertEqual(old_cell.getQuantity(), cell.getQuantity())
self.assertEqual(old_cell.getTotalQuantity(), cell.getTotalQuantity()) self.assertEqual(old_cell.getTotalQuantity(), cell.getTotalQuantity())
......
...@@ -257,7 +257,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -257,7 +257,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual([],folder_object_list) self.assertEqual([],folder_object_list)
person = person_module.newContent(id='4',portal_type='Person') person = person_module.newContent(id='4',portal_type='Person')
person_module.recursiveImmediateReindexObject() self.tic()
folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()] folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()]
self.assertEqual(['4'],folder_object_list) self.assertEqual(['4'],folder_object_list)
...@@ -286,7 +286,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -286,7 +286,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_catalog.manage_catalogClear() portal_catalog.manage_catalogClear()
person = person_module.newContent(id='4',portal_type='Person') person = person_module.newContent(id='4',portal_type='Person')
person_module.recursiveImmediateReindexObject() self.tic()
folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()] folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()]
self.assertEqual(['4'],folder_object_list) self.assertEqual(['4'],folder_object_list)
...@@ -1722,7 +1722,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1722,7 +1722,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
""" """
org_a = self._makeOrganisation(title='abc',default_address_city='abc') org_a = self._makeOrganisation(title='abc',default_address_city='abc')
module = self.getOrganisationModule() module = self.getOrganisationModule()
module.immediateReindexObject() self.tic()
# First try without aliases # First try without aliases
query1 = Query(parent_portal_type="Organisation") query1 = Query(parent_portal_type="Organisation")
query2 = Query(grand_parent_portal_type="Organisation Module") query2 = Query(grand_parent_portal_type="Organisation Module")
......
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