Use transaction annotations to avoid multiple document indexations
authorThierry Florac <tflorac@ulthar.net>
Sat, 17 Feb 2018 15:58:52 +0100
changeset 45 f503181e8b77
parent 44 84d2932b293f
child 46 e13ddd7964aa
Use transaction annotations to avoid multiple document indexations
src/pyams_content_es/index.py
--- a/src/pyams_content_es/index.py	Thu Feb 08 08:52:49 2018 +0100
+++ b/src/pyams_content_es/index.py	Sat Feb 17 15:58:52 2018 +0100
@@ -56,7 +56,10 @@
 def handle_modified_document(event):
     """Handle modified document"""
     document = event.object
-    ITransactionManager(document).get().addAfterCommitHook(index_document, kws={'document': document})
+    transaction = ITransactionManager(document).get()
+    if 'pyams_content_es.index_document' not in transaction.extension:
+        transaction.addAfterCommitHook(index_document, kws={'document': document})
+        transaction.extension['pyams_content_es.index_document'] = True
 
 
 @subscriber(IObjectRemovedEvent, context_selector=IDocumentIndexTarget)