From 762c1872404b092939d3789f59aafa042b927d64 Mon Sep 17 00:00:00 2001
From: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
Date: Mon, 31 Jan 2011 02:17:37 +0000
Subject: [PATCH] delay interaction so it happens once at end of transaction

This avoids resetting several times the dynamic methods,
and should mean faster BT installation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42785 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Interactor/PortalTypeClassInteractor.py    | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/Interactor/PortalTypeClassInteractor.py b/product/ERP5/Interactor/PortalTypeClassInteractor.py
index 1053565cde..03633913bd 100644
--- a/product/ERP5/Interactor/PortalTypeClassInteractor.py
+++ b/product/ERP5/Interactor/PortalTypeClassInteractor.py
@@ -28,11 +28,13 @@
 ##############################################################################
 
 from Products.ERP5Type.Interactor.Interactor import Interactor
+import transaction
+from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
 
 class PortalTypeClassInteractor(Interactor):
   """
     This interactor handles all the calls to resetDynamicDocuments
-    which must be trigered whenever some parts of ERP5 
+    which must be trigered whenever some parts of ERP5
     are modified and require to generate again accessors
     and dynamic properties.
   """
@@ -52,12 +54,20 @@ class PortalTypeClassInteractor(Interactor):
 
   def resetDynamic(self, method_call_object, *args, **kw):
     """
-    Call resetDynamicDocuments
+    Call resetDynamicDocuments at the end of the transaction
     """
     from Products.ERP5.ERP5Site import getSite
     # method_call_object might be an unwrapped DCWorflowDefinition method,
     # no even belonging to a container.
     portal = getSite()
     types_tool = getattr(portal, 'portal_types', None)
-    if types_tool is not None:
-      types_tool.resetDynamicDocuments()
+    if types_tool is None:
+      return
+
+    # XXX this could be a generic doOnceAtEndOfTransaction in
+    # Interactor baseclass
+    tv = getTransactionalVariable()
+    key = 'Interactor.PortalTypeClassInteractor.resetDynamic'
+    if key not in tv:
+      tv[key] = None
+      transaction.get().addBeforeCommitHook(types_tool.resetDynamicDocuments)
-- 
2.30.9