Clear catalog and reindex all objects in "pyams_index" script
authorThierry Florac <tflorac@ulthar.net>
Sat, 21 Jul 2018 00:10:00 +0200
changeset 877 957488ef021d
parent 876 233fbe2abe82
child 878 6bc257d7f53f
Clear catalog and reindex all objects in "pyams_index" script
src/pyams_content/site.py
--- a/src/pyams_content/site.py	Sat Jul 21 00:09:10 2018 +0200
+++ b/src/pyams_content/site.py	Sat Jul 21 00:10:00 2018 +0200
@@ -18,14 +18,13 @@
 
 # import interfaces
 from hypatia.interfaces import ICatalog
-from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_content.shared.site.interfaces import IContentLink
 from zope.intid.interfaces import IIntIds
 
 # import packages
 from pyams_utils.container import find_objects_providing
 from pyams_utils.registry import set_local_registry, get_utility
 from pyams_utils.site import site_factory
+from zope.interface import Interface
 
 
 def site_index(request):
@@ -35,13 +34,14 @@
         try:
             set_local_registry(application.getSiteManager())
             catalog = get_utility(ICatalog)
+            catalog.reset()
+            transaction.savepoint()
             intids = get_utility(IIntIds)
-            for document in find_objects_providing(application, IWfSharedContent):
+            for index, document in enumerate(find_objects_providing(application, Interface)):
                 print("Indexing: {0!r}".format(document))
                 catalog.reindex_doc(intids.register(document), document)
-            for document in find_objects_providing(application, IContentLink):
-                print("Indexing: {0!r}".format(document))
-                catalog.reindex_doc(intids.register(document), document)
+                if not index % 100:
+                    transaction.savepoint()
         finally:
             set_local_registry(None)
         transaction.commit()