From 6fb24a35ecd61eabff1dfd5f5a18be47a948502c Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Mon, 18 Mar 2019 17:55:59 +0100
Subject: [PATCH] Temporary version, using pickle (since json crashes; needs
 yaml)

---
 SciPost_v1/signalprocessors.py | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/SciPost_v1/signalprocessors.py b/SciPost_v1/signalprocessors.py
index cfab275a7..faac5943c 100644
--- a/SciPost_v1/signalprocessors.py
+++ b/SciPost_v1/signalprocessors.py
@@ -5,10 +5,14 @@ __license__ = "AGPL v3"
 from haystack import signals
 from haystack.exceptions import NotHandled
 
+from SciPost_v1.celery import app
 from submissions.models import Submission
 
 
 class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
+
+    @app.task(bind=True, name='signalprocessors.remove_object_indexes',
+              serializer='pickle')
     def remove_objects_indexes(self, sender, objects):
         """
         Given a set of `objects` model instances, remove them from the index as preparation
@@ -29,6 +33,8 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
                     # TODO: Maybe log it or let the exception bubble?
                     pass
 
+    @app.task(bind=True, name='signalprocessors.update_instance_indexes',
+              serializer='pickle')
     def update_instance_indexes(self, sender, instance):
         """
         Given an individual model instance, update its entire indexes.
@@ -51,11 +57,20 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
         if isinstance(instance, Submission):
             # Submission have complex status handling, so a status change should lead to
             # more drastic reindexing.
-            self.remove_objects_indexes(sender, instance.thread.public())
-            self.update_instance_indexes(sender, instance)
+            chain = (
+                self.remove_objects_indexes.s(sender, instance.thread.public())
+                |
+                self.update_instance_indexes.s(sender, instance)
+            )
+            chain()
+
         else:
             # Objects such as Reports, Comments, Commentaries, etc. may get rejected. This
             # does not remove them from the index. Therefore, do a complete rebuild_index
             # action on that specific instance every time the index signal is triggered.
-            self.remove_objects_indexes(sender, [instance])
-            self.update_instance_indexes(sender, instance)
+            chain = (
+                self.remove_objects_indexes.s(sender, [instance])
+                |
+                self.update_instance_indexes.s(sender, instance)
+            )
+            chain()
-- 
GitLab