SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 6fb24a35 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Temporary version, using pickle (since json crashes; needs yaml)

parent 03dc0e78
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,14 @@ __license__ = "AGPL v3" ...@@ -5,10 +5,14 @@ __license__ = "AGPL v3"
from haystack import signals from haystack import signals
from haystack.exceptions import NotHandled from haystack.exceptions import NotHandled
from SciPost_v1.celery import app
from submissions.models import Submission from submissions.models import Submission
class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor): class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
@app.task(bind=True, name='signalprocessors.remove_object_indexes',
serializer='pickle')
def remove_objects_indexes(self, sender, objects): def remove_objects_indexes(self, sender, objects):
""" """
Given a set of `objects` model instances, remove them from the index as preparation Given a set of `objects` model instances, remove them from the index as preparation
...@@ -29,6 +33,8 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor): ...@@ -29,6 +33,8 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
# TODO: Maybe log it or let the exception bubble? # TODO: Maybe log it or let the exception bubble?
pass pass
@app.task(bind=True, name='signalprocessors.update_instance_indexes',
serializer='pickle')
def update_instance_indexes(self, sender, instance): def update_instance_indexes(self, sender, instance):
""" """
Given an individual model instance, update its entire indexes. Given an individual model instance, update its entire indexes.
...@@ -51,11 +57,20 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor): ...@@ -51,11 +57,20 @@ class AutoSearchIndexingProcessor(signals.RealtimeSignalProcessor):
if isinstance(instance, Submission): if isinstance(instance, Submission):
# Submission have complex status handling, so a status change should lead to # Submission have complex status handling, so a status change should lead to
# more drastic reindexing. # more drastic reindexing.
self.remove_objects_indexes(sender, instance.thread.public()) chain = (
self.update_instance_indexes(sender, instance) self.remove_objects_indexes.s(sender, instance.thread.public())
|
self.update_instance_indexes.s(sender, instance)
)
chain()
else: else:
# Objects such as Reports, Comments, Commentaries, etc. may get rejected. This # Objects such as Reports, Comments, Commentaries, etc. may get rejected. This
# does not remove them from the index. Therefore, do a complete rebuild_index # 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. # action on that specific instance every time the index signal is triggered.
self.remove_objects_indexes(sender, [instance]) chain = (
self.update_instance_indexes(sender, instance) self.remove_objects_indexes.s(sender, [instance])
|
self.update_instance_indexes.s(sender, instance)
)
chain()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment