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