From a338b267c297aed7a5e5e3e61814144ac55efb47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Fri, 9 Nov 2007 15:02:49 +0000
Subject: [PATCH] do no recall reindeObject when object goes in archive except
 if explicitly specified, thus we index everything at one time preventing from
 retrieving same objects many times from different node

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17494 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ZSQLCatalog/ZSQLCatalog.py | 36 +++++++++++++++++-------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/product/ZSQLCatalog/ZSQLCatalog.py b/product/ZSQLCatalog/ZSQLCatalog.py
index 2203a3a1f1..ea49e0ad47 100644
--- a/product/ZSQLCatalog/ZSQLCatalog.py
+++ b/product/ZSQLCatalog/ZSQLCatalog.py
@@ -686,7 +686,8 @@ class ZCatalog(Folder, Persistent, Implicit):
     """ wrapper around catalog """
     self.catalogObjectList([obj], sql_catalog_id=sql_catalog_id)
 
-  def catalogObjectList(self, object_list, sql_catalog_id=None, disable_archive=0, **kw):
+  def catalogObjectList(self, object_list, sql_catalog_id=None, disable_archive=0,
+                        immediate_reindex_archive=1, **kw):
     """Catalog a list of objects.
     """
     catalog = self.getSQLCatalog(sql_catalog_id)
@@ -783,28 +784,33 @@ class ZCatalog(Folder, Persistent, Implicit):
           # if we reindex in current catalog, do not relaunch an activity for this
           continue
         d = catalog_dict[catalog_id]
+        # build the wrapped object list
+        wrapped_object_list_2 = []
+        for obj in d['obj']:
+          try:
+            wrap_obj = self.wrapObject(obj, sql_catalog_id=catalog_id)
+          except ConflictError:
+            raise
+          except:
+            LOG('WARNING ZSQLCatalog', 0, 'wrapObject failed on the object %r' % (obj,), error=sys.exc_info())
+            failed_object_list.append(obj)
+          wrapped_object_list_2.append(wrap_obj)
+
         # hot_reindexing is True when creating an object during a hot reindex, in this case, we don't want
         # to reindex it in destination catalog, it will be recorded an play only once
         if not hot_reindexing and self.hot_reindexing_state != HOT_REINDEXING_DOUBLE_INDEXING_STATE and \
                self.destination_sql_catalog_id == catalog_id:
           destination_catalog = self.getSQLCatalog(self.destination_sql_catalog_id)
-          # wrap all objects
-          wrapped_object_list_2 = []
-          for obj in d['obj']:
-            try:
-              wrap_obj = self.wrapObject(obj, sql_catalog_id=catalog_id)
-            except ConflictError:
-              raise
-            except:
-              LOG('WARNING ZSQLCatalog', 0, 'wrapObject failed on the object %r' % (obj,), error=sys.exc_info())
-              failed_object_list.append(obj)
-            wrapped_object_list_2.append(wrap_obj)
           # reindex objects in destination catalog
           destination_catalog.catalogObjectList(wrapped_object_list_2, **kw)
         else:
-          for obj in d['obj']:
-            obj._reindexObject(sql_catalog_id=catalog_id, activate_kw = \
-                              {'priority': d['priority']}, disable_archive=1, **kw)
+          archive_catalog = self.getSQLCatalog(catalog_id)
+          if immediate_reindex_archive:
+            archive_catalog.catalogObjectList(wrapped_object_list_2, **kw)
+          else:
+            for obj in d['obj']:
+              obj._reindexObject(sql_catalog_id=catalog_id, activate_kw = \
+                                 {'priority': d['priority']}, disable_archive=1, **kw)
     
     if catalog is not None:
       if len(wrapped_object_list):
-- 
2.30.9