Commit 95f3f8f5 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Speed up reset in __of__.

parent d702bf05
...@@ -340,15 +340,15 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -340,15 +340,15 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
tv['ERP5Site.__of__'] = None tv['ERP5Site.__of__'] = None
setSite(self) setSite(self)
# If Components are reset, then portal type classes should be reset
try: try:
reset_portal_type = self.portal_components.reset(force=False, component_tool = self.portal_components
reset_portal_type=False)
# This should only happen before erp5_core is installed
except AttributeError: except AttributeError:
reset_portal_type = False # This should only happen before erp5_core is installed
synchronizeDynamicModules(self)
else:
# If Components are reset, then portal type classes should be reset
synchronizeDynamicModules(self, component_tool.reset())
synchronizeDynamicModules(self, force=True)
return self return self
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
......
...@@ -56,7 +56,7 @@ class ComponentTool(BaseTool): ...@@ -56,7 +56,7 @@ class ComponentTool(BaseTool):
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.ResetDynamicClasses, 'reset') security.declareProtected(Permissions.ResetDynamicClasses, 'reset')
def reset(self, force=True, reset_portal_type=True): def reset(self, force=False, reset_portal_type=False):
""" """
XXX-arnau: global reset XXX-arnau: global reset
""" """
...@@ -115,4 +115,5 @@ class ComponentTool(BaseTool): ...@@ -115,4 +115,5 @@ class ComponentTool(BaseTool):
key = 'ComponentTool.resetOnceAtTransactionBoundary' key = 'ComponentTool.resetOnceAtTransactionBoundary'
if key not in tv: if key not in tv:
tv[key] = None tv[key] = None
transaction.get().addBeforeCommitHook(self.reset) transaction.get().addBeforeCommitHook(self.reset,
args=(True, True))
...@@ -1254,7 +1254,7 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1254,7 +1254,7 @@ class _TestZodbComponent(SecurityTestCase):
self._component_tool = self.getPortal().portal_components self._component_tool = self.getPortal().portal_components
self._module = __import__(self._getComponentModuleName(), self._module = __import__(self._getComponentModuleName(),
fromlist=['erp5.component']) fromlist=['erp5.component'])
self._component_tool.reset() self._component_tool.reset(force=True, reset_portal_type=True)
@abc.abstractmethod @abc.abstractmethod
def _newComponent(self, reference, text_content, version='erp5'): def _newComponent(self, reference, text_content, version='erp5'):
...@@ -1362,7 +1362,7 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1362,7 +1362,7 @@ class _TestZodbComponent(SecurityTestCase):
self.assertEquals(error_message, error_list[0]) self.assertEquals(error_message, error_list[0])
self.assertEquals(component.getReference(), invalid_reference) self.assertEquals(component.getReference(), invalid_reference)
self.assertEquals(component.getReference(validated_only=True), valid_reference) self.assertEquals(component.getReference(validated_only=True), valid_reference)
self._component_tool.reset() self._component_tool.reset(force=True, reset_portal_type=True)
self.assertModuleImportable(valid_reference) self.assertModuleImportable(valid_reference)
ComponentTool.reset = assertResetCalled ComponentTool.reset = assertResetCalled
...@@ -1430,7 +1430,7 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1430,7 +1430,7 @@ class _TestZodbComponent(SecurityTestCase):
self.assertEquals(error_message, error_list[0]) self.assertEquals(error_message, error_list[0])
self.assertEquals(component.getVersion(), invalid_version) self.assertEquals(component.getVersion(), invalid_version)
self.assertEquals(component.getVersion(validated_only=True), valid_version) self.assertEquals(component.getVersion(validated_only=True), valid_version)
self._component_tool.reset() self._component_tool.reset(force=True, reset_portal_type=True)
self.assertModuleImportable(reference) self.assertModuleImportable(reference)
ComponentTool.reset = assertResetCalled ComponentTool.reset = assertResetCalled
...@@ -1495,7 +1495,7 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1495,7 +1495,7 @@ class _TestZodbComponent(SecurityTestCase):
self.assertTrue(error_list[0].startswith(error_message)) self.assertTrue(error_list[0].startswith(error_message))
self.assertEquals(component.getTextContent(), invalid_code) self.assertEquals(component.getTextContent(), invalid_code)
self.assertEquals(component.getTextContent(validated_only=True), valid_code) self.assertEquals(component.getTextContent(validated_only=True), valid_code)
self._component_tool.reset() self._component_tool.reset(force=True, reset_portal_type=True)
self.assertModuleImportable('TestComponentWithSyntaxError') self.assertModuleImportable('TestComponentWithSyntaxError')
ComponentTool.reset = assertResetCalled ComponentTool.reset = assertResetCalled
...@@ -1780,7 +1780,7 @@ class TestPortalType(Person): ...@@ -1780,7 +1780,7 @@ class TestPortalType(Person):
self.assertFalse(self._module.TestPortalType in person.__class__.mro()) self.assertFalse(self._module.TestPortalType in person.__class__.mro())
# Reset Portal Type classes to ghost to make sure that everything is reset # Reset Portal Type classes to ghost to make sure that everything is reset
self._component_tool.reset() self._component_tool.reset(force=True, reset_portal_type=True)
# TestPortalType must be in available type class list # TestPortalType must be in available type class list
self.assertTrue('TestPortalType' in person_type.getDocumentTypeList()) self.assertTrue('TestPortalType' in person_type.getDocumentTypeList())
......
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